AWS Rekognition gives InvalidS3Exeption error

Every time I run a command

aws rekognition detect-labels --image "S3Object={Bucket=BucketName,Name=picture.jpg}" --region us-east-1

I get this error.

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

I'm trying to get shortcuts for a project I'm working on, but I can't go through this step. I configured aws with my passkey, secret key, us-east-1 region and json as the output format.

I also tried the code below and I got exactly the same error (I correctly replaced BucketName with the name of my bucket.)

import boto3

BUCKET = "BucketName"
KEY = "picture.jpg"

def detect_labels(bucket, key, max_labels=10, min_confidence=90, region="eu-west-1"):
    rekognition = boto3.client("rekognition", region)
    response = rekognition.detect_labels(
        Image={
            "S3Object": {
                "Bucket": bucket,
                "Name": key,
            }
        },
        MaxLabels=max_labels,
        MinConfidence=min_confidence,
    )
    return response['Labels']


for label in detect_labels(BUCKET, KEY):
    print "{Name} - {Confidence}%".format(**label)

I can see in my account that it calls Rekognition. Image showing that it is being called from the IAM.

It seems that the problem is somewhere with my S3 basket, but I did not find out that.

+5
source share

Source: https://habr.com/ru/post/1679192/


All Articles