'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?



Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

Ensure bucket region is same as calling region. If you are using AWS CLI then make sure to include profile with appropriate region.

Solution 4:[4]

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

Solution 5:[5]

It seems to me that you dont have enough permissions with that access_key and secret_key! If the credentials are of an IAM user, make sure the IAM user has permission to perform Rekognition compare_faces read operations and s3 read operations! Also check if your s3 source and target object key are correct. And it is better to create roles with required permissions and assume that role to request temporary security credentials instead of using the permanent access keys.

Solution 6:[6]

Please ensure the AWS environment variable configuration AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY in your script before compile

Solution 7:[7]

Also ran into this issue, noticed my IAM role had the bucketname as the resource, i had to add a slash and a wildcard to the end. changed it to "Resource": "arn:aws:s3:::/*"

Solution 8:[8]

For me changing the file permissions in the S3 bucket worked.

Solution 9:[9]

For me the problem was the name of the file in s3 Bucket containing Spaces. So you have to make sure the key doesn't contain spaces while storing itself.

Solution 10:[10]

I had the same error: I checked and found out that the image was present in some subfolder of the bucket. Make sure that the image is in the root bucket.

Solution 11:[11]

In my case I had the path to my object prefixed with a slash (/). Removing it did the trick.

Solution 12:[12]

Although this is a very old question, but I also had the same issue. But In my case, I was using the Lambda and my Lambda role didn't had the access to S3, so if you are doing it through Lambda, you need to provide the S3 access to it in addition to Rekognition.