Skip to content

S3 permission error when calling the DetectFaces operation

0

We have been using the same code for more than 2 years, but suddenly everything is failing with the error message of

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

The regions are the same, the I'AM user has S3 full access and Rekognition full access.

import boto3
import json

def detect_faces(photo):

    client=boto3.client('rekognition')
    s3 = boto3.client("s3")

    s3.upload_file(
    Bucket='bucketname', Key=photo, Filename=photo
    )

    response = client.detect_faces(Image={'S3Object':{'Bucket':'bucketname','Name':photo}},Attributes=['ALL'])


How do I fix this?

2 Answers
0

Are there any "Deny" statements in the S3 bucket policy? Are ACLs disabled for the bucket, meaning that the object ownership setting on the bucket's permissions tab shows "bucket owner enforced"?

If there are no "denies" in the bucket policy and if ACLs are disabled, is the bucket set to use SSE-S3 or SSE-KMS as the default encryption method? If it's SSE-KMS, you could open the event history view in the CloudTrail console in the same region, expose the "error code" column from behind the gear symbol in the upper right-hand corner, and search by the "Event name" field containing "GenerateDataKey" or "Decrypt". Does either filter return events containing AccessDenied or another error in the error code column? If so, it would mean that your IAM role doesn't have permissions to the KMS key; or that the KMS key policy doesn't grant access to the role or delegate authority to IAM in the account; or that the KMS key has been deactivated or deleted.

If none of the above apply, and assuming that your IAM role hasn't been modified since the last time your code worked, access could also be blocked by a service control policy (SCP) set by your AWS Organizations organisation, or enforced by a VPC endpoint policy of an S3 VPC endpoint that your requests might be going through.

EXPERT

answered 2 years ago

  • Thank you for your reply, The code was working as it is till yesterday, It only broke today. There are no "Deny" statements in the S3 bucket policy, the ACLs are also disabled for the bucket. We are using SSE-S3. The I'AM user has both "AmazonRekognitionFullAccess" and "AmazonS3FullAccess".

0

Hi,

Your administrator might have applied or enabled the scp at org level for deny.

Thanks

answered 2 years ago

  • I'm the root user and when on AWS Organizations: Service control policies (SCPs) in IAM menu, I get an error of "Your request has a problem. Please see the following details. Your account is not a member of an organization."

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Relevant content