Search code examples
amazon-web-servicesamazon-s3amazon-textract

Not able to access file in S3Bucket


I'm a total newbie in AWS trying to use Textract. Right now I have a file in the S3Bucket and I'm trying to process it through the API. I'm using the following code (I'm running it in Python):

# Document
            s3BucketName = "textract-console-us-east-1-057eddde-3f44-45c5-9208-fec27f9f6420"
            documentName = "ok0001_prioridade01.pdf"


            # Amazon Textract client
            textract = boto3.client('textract',region_name="us-east-1",aws_access_key_id="xxxx",
                                    aws_secret_access_key="xxxx")


            # Call Amazon Textract
            response = textract.analyze_document(
                Document={
                    'S3Object': {
                        'Bucket': s3BucketName,
                        'Name': documentName
                    }
                },
                FeatureTypes=["TABLES"])

I'm getting this error:

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

Then when I log the console I access the bucket and the file, and when I try to access the file in the above link, I get to this xml error page.

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>xxxx</RequestId>
<HostId>xxxxxxxxxxxxxx</HostId>
</Error>

So I get to wonder why is my access denied. I log back to IAM to see if I've messed something up, however the permissions are applied to my user:

enter image description here

What am I missing? Why ain't I able to access the file through the console (and consequently through API)?


Solution

  • The S3 object url will only work if the object is public. To download it through S3 console you have to Download it using S3 object menu for that:

    enter image description here