pythonamazon-web-servicesamazon-rekognition

python boto3: AWS Rekognition is unable to access S3 bucket


I am trying to upload the image to S3 and then have AWS Rekognition fetch it from S3 for face detection, but Rekognition cannot do that.

Here is my code - uploading and then detecting:

import boto3

s3 = boto3.client('s3')
s3.put_object(
    ACL='public-read',
    Body=open('/Users/1111/Desktop/kitten800300/kitten.jpeg', 'rb'),
    Bucket='mobo2apps',
    Key='kitten_img.jpeg'
)

rekognition = boto3.client('rekognition')

response = rekognition.detect_faces(
    Image={
        'S3Object': {
            'Bucket': 'mobo2apps',
            'Name': 'kitten_img.jpeg',
        }
    }

)

this produces an error:

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

Why is that?

About the permissions: I am authorized with AWS root access keys, so I have full access to all resources.


Solution

  • Here are the few things that you can do:

    1. Make sure the region of the S3 bucket is the same as Recognition. Otherwise, it won't work. S3 service is global but every bucket is created in a specific region. The same region should be used by AWS clients.
    2. Make sure the access keys of the user or role have the right set of permissions for the resource.
    3. Make sure the file is actually uploaded.
    4. Make sure there is no bucket policy applied that revokes access.
    5. You can enable logging on your S3 bucket to see errors.
    6. Make sure the bucket is not versioned. If versioned, specify the object version.
    7. Make sure the object has the correct set of ACLs defined.
    8. If the object is encrypted, make sure you have permission to use that KMS key to decrypt the object.