Reputation: 96
When I start a textract StartDocumentTextDetection and try to set the NotificationChannel as follows
response = client.start_document_text_detection(
DocumentLocation={
'S3Object': {
'Bucket': s3BucketName,
'Name': objectName
},
},
ClientRequestToken='string',
JobTag='string',
NotificationChannel={
'RoleArn': snsRoleArn,
'SNSTopicArn': snsTopicArn
}
)
I am getting an InvalidParameterException
An error occurred (InvalidParameterException) when calling the StartDocumentTextDetection operation: Request has invalid parameters
python 3.7 boto3 1.12.35
Upvotes: 1
Views: 2440
Reputation: 25
I got the same issue and I removed the JobTag. Then it's solved.
# Call Amazon Textract
response = textract_client.start_document_text_detection(
DocumentLocation={
'S3Object': {
'Bucket': 's3BucketName',
'Name': 'documentName'
}
},
NotificationChannel={
'SNSTopicArn': 'arn:aws:sns:us-east-1:192xxxxxxxx:AmazonTextractTopic',
'RoleArn': 'arn:aws:iam::192xxxxxxxx:role/AWSTextractRole'
}
)
Upvotes: 1
Reputation: 3180
I was able to run your code snippet with minimal modification as illustrated below:
import boto3
session = boto3.Session(profile_name='syumaK')
# Any clients created from this session will use credentials
# from the [dev] section of ~/.aws/credentials.
# Document
s3BucketName = 'syumaK-bucket'
documentName = 'document.pdf'
# Amazon Textract client
textract_client = session.client('textract')
# Call Amazon Textract
response = textract_client.start_document_text_detection(
DocumentLocation={
'S3Object': {
'Bucket': 's3BucketName',
'Name': 'documentName'
}
},
JobTag='Receipt',
NotificationChannel={
'SNSTopicArn': 'arn:aws:sns:us-east-1:192xxxxxxxx:AmazonTextractTopic',
'RoleArn': 'arn:aws:iam::192xxxxxxxx:role/AWSTextractRole'
}
)
#print(response)
print(response)
The successful published message from Amazon Textract to SNS topic should output something similar to:
{'JobId': '83111ff3cf665225dde114f796972c3cbf9b663170e778c291666c7eaf57c5d0', 'ResponseMetadata': {'RequestId': 'b3ce4fc9-9a6e-4b9a-ba4b-c849b9763405', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 11 Apr 2020 07:48:07 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '76', 'connection': 'keep-alive', 'x-amzn-requestid': 'b3ce4fc9-9a6e-4b9a-ba4b-c849b9763405'}, 'RetryAttempts': 0}}
Below is some tips for consideration in-case anyone else runs into this issue :
If the document to be processed is located in an S3 folder then the params needs to be changed as follows:
DocumentLocation={
'S3Object': {
'Bucket': 's3BucketName',
'Name': 'folder/documentName'
}
},
Hope this helps.
Upvotes: 1