Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get object metadata from S3. Check object key, region and/or access permissions in aws Rekognition

import boto3

if __name__ == "__main__":

    bucket='MyBucketName'
sourceFile='pic1.jpg'
targetFile='pic2.jpg'

client=boto3.client('rekognition','us-east-1')

response=client.compare_faces(SimilarityThreshold=70,
                              SourceImage={'S3Object':{'Bucket':bucket,'Name':sourceFile}},
                              TargetImage={'S3Object':{'Bucket':bucket,'Name':targetFile}})

for faceMatch in response['FaceMatches']:
    position = faceMatch['Face']['BoundingBox']
    confidence = str(faceMatch['Face']['Confidence'])
    print('The face at ' +
           str(position['Left']) + ' ' +
           str(position['Top']) +
           ' matches with ' + confidence + '% confidence')

I am trying to compare two images present in my bucket but no matter which region i select i always get the following error:-

botocore.errorfactory.InvalidS3ObjectException: An error occurred (InvalidS3ObjectException) when calling the CompareFaces operation: Unable to get object metadata from S3. Check object key, region and/or access permissions.

My bucket's region is us-east-1 and I have configured the same in my code. what am I doing wrong?

like image 475
Harsh Vardhan Parashar Avatar asked May 04 '18 18:05

Harsh Vardhan Parashar


3 Answers

It happened to me using the AWS rekognition sdk for android , the problem was that the region of the S3 bucket is not the same in my request , so I had to put the correct region in the request (same as S3 bucket ) :

 rekognitionClient.setRegion(Region.getRegion(Regions.US_WEST_1));//replace with your S3 region
like image 110
Mohammed Fathi Avatar answered Sep 23 '22 20:09

Mohammed Fathi


I had the same problem. What I did to fix it was to rearrange my bucket and the folders. Make sure that your image is directly in your bucket and not in a folder in your bucket. Also double check that the name of the images are correct and that everything is on point.

like image 11
Sean Li Avatar answered Oct 18 '22 21:10

Sean Li


Check if the S3 and Image Rekognition is in the same region, I know, it's not nice or documented (I guess), but this guys are talking about it here and here

like image 9
Italo José Avatar answered Oct 18 '22 22:10

Italo José