kev
kev

Reputation: 1115

Invalid Request for Boto3 Call to Textract

I am trying to make a boto3 call to Textract, but am unable to see what's wrong with my code. This is the error message I got:

Traceback (most recent call last):
  File "run.py", line 20, in <module>
    'RoleArn': 'arn:aws:iam::xxxxxxxxxxxx:role/xxxRole'
  File "/Users/xxx/venv/lib/python3.4/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/xxx/venv/lib/python3.4/site-packages/botocore/client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the StartDocumentAnalysis operation: Request has invalid parameters

This is my code

import boto3

client = boto3.client('textract')

response = client.start_document_analysis(
  DocumentLocation={
    'S3Object': {
      'Bucket': 'xxx',
      'Name': 'xxx.pdf'
    }
  },
  FeatureTypes=[
    'TABLES',
    'FORMS'
  ],
  ClientRequestToken='xxx',
  JobTag='xxx',
  NotificationChannel={
    'SNSTopicArn': 'arn:aws:sns:us-east-2:xxx:xxx',
    'RoleArn': 'arn:aws:iam::xxx:role/xxxRole'
  }
)

I have tried recreating my SNS topic and service roles several times, as well as making sure that my tabs/spaces are correct (for Python's sake). I've also switched the positions of SNSTopicArn and RoleArn, and the error message shows that SNSTopicArn to be the line in question now.

Any help appreciated.

Upvotes: 3

Views: 3691

Answers (1)

kev
kev

Reputation: 1115

It was pretty silly - I specified the "folder" in the bucket name, when it should be part of the document name.

E.g. bucket-name/folder/document.png

Bucket name should be "bucket-name" and object name should be "folder/document.png".

Upvotes: 3

Related Questions