0
votes

I'm getting below error when I execute Rekognition using Image or Video (s3 source).

" Error executing "SearchFacesByImage" on "https://rekognition.us-east-1.amazonaws.com"; AWS HTTP error: Client error: POST https://rekognition.us-east-1.amazonaws.com resulted in a 400 Bad Request response: {"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException","Logref":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"," (truncated...) InvalidS3ObjectException (client): Unable to get object metadata from S3. Check object key, region and/or access permissions. - {"__type":"InvalidS3ObjectException","Code":"InvalidS3ObjectException.

My as code Below.

$credentials = new Credentials('xxxxxxxxx', 'xxxxxxxxxxxx');

$rekognitionClient = RekognitionClient::factory(array(
            'region' => "us-east-1",
            'version' => 'latest',
            'credentials' => $credentials,
            'http' => [ 'verify' => false ]
 ));

$result = $rekognitionClient->searchFacesByImage([
                    'CollectionId' => ''.$collection_id.'', // REQUIRED
                    'FaceMatchThreshold' => 25.0,
                    'Image' => [ // REQUIRED
                            'S3Object' => [
                                'Bucket' => 'facetracking',
                                'Name' => 'test.jpg',
                                'Key' => 'test.jpg',
                                'Version' => 'latest',
                            ],
                    ], 'MaxFaces' => 2,
                ]);

When I'm uploading into S3, Getting an object from S3 and creating a collection in Rekognition All Its works fine but I can't execute searchFacesByImage (Source: S3) and startFaceSearch in Laravel PHP.

Also tired after bucket policy setup in S3 like below.

{
    "Version": "2012-10-17",
    "Id": "PolicyXXXXXX",
    "Statement": [
        {
            "Sid": "StmtXXXXXX",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::XXXXXXXX:root"
            },
            "Action": [
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:GetObjectTagging",
                "s3:GetObjectTorrent",
                "s3:GetObjectVersion",
                "s3:GetObjectVersionAcl"
            ],
            "Resource": [
                "arn:aws:s3:::<MyBucketName>/*",
                "arn:aws:s3:::<MyBucketName>"
            ]
        }
    ]
}
2

2 Answers

1
votes

Another strange reason this error pops up is because your bucket permissions might be to strict.

I was getting this error when allowing all actions on this specific bucket ARN. When I replaced the ARN with *it worked perfectly.

Really odd, and I'm not sure why this works, but hopefully it might help someone.

0
votes

Problem solved by removing version. Because my bucket versioning disabled. 'Version' => '<String>', // REQUIRED Only if Bucket versioning enabled

Version

Version Only Required If the bucket is versioning enabled, you can specify the object version.

Required: No

https://github.com/aws/aws-sdk-php-laravel/issues/139

$result = $rekognitionClient->searchFacesByImage([
                    'CollectionId' => ''.$collection_id.'', // REQUIRED
                    'FaceMatchThreshold' => 25.0,
                    'Image' => [ // REQUIRED
                            'S3Object' => [
                                'Bucket' => 'facetracking',
                                'Name' => 'test.jpg',
                                'Key' => 'test.jpg',
                            ],
                    ], 'MaxFaces' => 2,
                ]);