Harsh Vardhan Parashar
Harsh Vardhan Parashar

Reputation: 265

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?

Upvotes: 19

Views: 42170

Answers (17)

TheReal2bz
TheReal2bz

Reputation: 11

I just had to create the respective folder in my S3 bucket and upload the file. Everything worked fine.

Upvotes: 0

Kaushik Shrimali
Kaushik Shrimali

Reputation: 1

There are many reasons to did not connect s3 file.

  1. Check your region
  2. Verify your bucket policy
  3. Check IAM user region and your s3 bucket region. it will help you

Upvotes: 0

SKN
SKN

Reputation: 11

Ran into similar issue, and figured out it is due to having space in any of the folder name.

Upvotes: 1

Koushik Samanta
Koushik Samanta

Reputation: 225

I faced a similar problem like

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

It may be due to wrong AWS region, key or Permission was not given properly.

In my case the wrong region was set as an environment variable.

Upvotes: 3

Hermann
Hermann

Reputation: 11

Same error mesagge but using Textract functions, no problem with permissions, but my files in s3 containing special caracters, once I renamed the files there was no problem.

Upvotes: 1

Shipra Sahu
Shipra Sahu

Reputation: 1

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.

Upvotes: 0

spaceemotion
spaceemotion

Reputation: 1546

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

Upvotes: 1

yogender
yogender

Reputation: 586

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.

Upvotes: 0

Rajesh Kanna
Rajesh Kanna

Reputation: 143

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.

Upvotes: 1

Gennaro
Gennaro

Reputation: 138

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

Upvotes: 0

Mohammed Fathi
Mohammed Fathi

Reputation: 1475

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

Upvotes: 2

Italo José
Italo José

Reputation: 1686

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

Upvotes: 15

Tejas Mahale
Tejas Mahale

Reputation: 61

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

Upvotes: 4

Jeffrey DeMuth
Jeffrey DeMuth

Reputation: 139

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:::/*"

Upvotes: 0

Sean Li
Sean Li

Reputation: 138

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.

Upvotes: 12

Manoj Acharya
Manoj Acharya

Reputation: 1479

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.

Upvotes: 1

Venkatesh Kuppusamy
Venkatesh Kuppusamy

Reputation: 73

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

Upvotes: 0

Related Questions