Prashanth
Prashanth

Reputation: 96

InvalidParameterException when starting a Textract job using SNS Notification channel

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

Answers (2)

hburak_06
hburak_06

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

aksyuma
aksyuma

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 :

  • Make sure you are using valid values for SNSTopicArn & RoleArn
  • 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

Related Questions