简体   繁体   中英

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.

You have to wait for a while that the image uploading is done.

The code looks running smoothly, so your jpeg starts to upload and even before the uploading is finished, Rekognition starts to detect the face from the image. Since the uploading is not finished when the code runs, it cannot find the object from your S3. Put a wait time a bit.

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 for the resource has the right set of permissions.
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM