boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
8.98k stars 1.86k forks source link

InvalidParameterException when starting a Textract job with SNS Notification channel as parameter #2379

Closed prashanthayyavu closed 4 years ago

prashanthayyavu commented 4 years ago

I use python 3.7 and boto3 1.12.35 versions.

When I start a Amazon 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

The issue can be reproduced using the following simple code snippet. Please use appropriate values for s3 object and sns

import boto3

s3 = boto3.resource('s3')

textractClient = boto3.client('textract', region_name= 'us-east-2')

response = textractClient.start_document_text_detection(
    DocumentLocation={
        'S3Object': {
            'Bucket': "bucketName", 
            'Name': "s3ObjectName"
        }
    },
    NotificationChannel={
        'RoleArn': "snsRoleArn", 
        'SNSTopicArn': "snsTopicArn"
    }
)

logs

Traceback (most recent call last): File "/Users/prashanthayyavu/repo/personal/pdf_to_els/src/notification_issue.py", line 12, in NotificationChannel={'RoleArn': snsRoleArn, 'SNSTopicArn': snsTopicArn}) File "/Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call return self._make_api_call(operation_name, kwargs) File "/Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/client.py", line 626, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the StartDocumentTextDetection operation: Request has invalid parameters

swetashre commented 4 years ago

@prashanthayyavu - Thank you for your post.InvalidParameterException occurs if an input parameter has violated any constraint. Can you please provide me full debug log ? You can enable log by adding boto3.set_stream_logger('') to your code.

prashanthayyavu commented 4 years ago

@swetashre here you go.

/Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/bin/python /Users/prashanthayyavu/repo/personal/pdf_to_els/src/notification_issue.py 2020-04-09 15:40:27,980 botocore.hooks [DEBUG] Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane 2020-04-09 15:40:27,983 botocore.hooks [DEBUG] Changing event name from before-call.apigateway to before-call.api-gateway 2020-04-09 15:40:27,983 botocore.hooks [DEBUG] Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict 2020-04-09 15:40:27,985 botocore.hooks [DEBUG] Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration 2020-04-09 15:40:27,985 botocore.hooks [DEBUG] Changing event name from before-parameter-build.route53 to before-parameter-build.route-53 2020-04-09 15:40:27,986 botocore.hooks [DEBUG] Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search 2020-04-09 15:40:27,987 botocore.hooks [DEBUG] Changing event name from docs..autoscaling.CreateLaunchConfiguration.complete-section to docs..auto-scaling.CreateLaunchConfiguration.complete-section 2020-04-09 15:40:27,990 botocore.hooks [DEBUG] Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask 2020-04-09 15:40:27,991 botocore.hooks [DEBUG] Changing event name from docs..logs.CreateExportTask.complete-section to docs..cloudwatch-logs.CreateExportTask.complete-section 2020-04-09 15:40:27,991 botocore.hooks [DEBUG] Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search 2020-04-09 15:40:27,991 botocore.hooks [DEBUG] Changing event name from docs..cloudsearchdomain.Search.complete-section to docs..cloudsearch-domain.Search.complete-section 2020-04-09 15:40:28,023 botocore.loaders [DEBUG] Loading JSON file: /Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/boto3/data/s3/2006-03-01/resources-1.json 2020-04-09 15:40:28,043 botocore.credentials [DEBUG] Looking for credentials via: env 2020-04-09 15:40:28,043 botocore.credentials [DEBUG] Looking for credentials via: assume-role 2020-04-09 15:40:28,044 botocore.credentials [DEBUG] Looking for credentials via: assume-role-with-web-identity 2020-04-09 15:40:28,044 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file 2020-04-09 15:40:28,044 botocore.credentials [INFO] Found credentials in shared credentials file: ~/.aws/credentials 2020-04-09 15:40:28,045 botocore.loaders [DEBUG] Loading JSON file: /Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/data/endpoints.json 2020-04-09 15:40:28,050 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x10a319830> 2020-04-09 15:40:28,061 botocore.loaders [DEBUG] Loading JSON file: /Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/data/s3/2006-03-01/service-2.json 2020-04-09 15:40:28,068 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x10a2ef7a0> 2020-04-09 15:40:28,068 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function lazy_call.._handler at 0x10a41d200> 2020-04-09 15:40:28,109 botocore.hooks [DEBUG] Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x10a2ef560> 2020-04-09 15:40:28,112 botocore.endpoint [DEBUG] Setting s3 timeout as (60, 60) 2020-04-09 15:40:28,113 botocore.loaders [DEBUG] Loading JSON file: /Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/data/_retry.json 2020-04-09 15:40:28,113 botocore.client [DEBUG] Registering retry handlers for service: s3 2020-04-09 15:40:28,114 boto3.resources.factory [DEBUG] Loading s3:s3 2020-04-09 15:40:28,116 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x10a319830> 2020-04-09 15:40:28,116 botocore.loaders [DEBUG] Loading JSON file: /Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/data/textract/2018-06-27/service-2.json 2020-04-09 15:40:28,117 botocore.hooks [DEBUG] Event creating-client-class.textract: calling handler <function add_generate_presigned_url at 0x10a2ef560> 2020-04-09 15:40:28,118 botocore.regions [DEBUG] Creating a regex based endpoint for textract, us-east-2 2020-04-09 15:40:28,119 botocore.endpoint [DEBUG] Setting textract timeout as (60, 60) 2020-04-09 15:40:28,120 botocore.client [DEBUG] Registering retry handlers for service: textract 2020-04-09 15:40:28,120 botocore.hooks [DEBUG] Event before-parameter-build.textract.StartDocumentTextDetection: calling handler <function generate_idempotent_uuid at 0x10a33edd0> 2020-04-09 15:40:28,121 botocore.hooks [DEBUG] Event before-call.textract.StartDocumentTextDetection: calling handler <function inject_api_version_header_if_needed at 0x10a3508c0> 2020-04-09 15:40:28,121 botocore.endpoint [DEBUG] Making request for OperationModel(name=StartDocumentTextDetection) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'X-Amz-Target': 'Textract.StartDocumentTextDetection', 'Content-Type': 'application/x-amz-json-1.1', 'User-Agent': 'Boto3/1.12.35 Python/3.7.7 Darwin/18.7.0 Botocore/1.15.35'}, 'body': b'{"DocumentLocation": {"S3Object": {"Bucket": "fds-pdf-files-temp", "Name": "ce111eda-17aa-4250-acc3-3b477ab1b162_Nexium.pdf"}}, "NotificationChannel": {"RoleArn": "arn:aws:iam::004805068978:root", "SNSTopicArn": "arn:aws:sns:us-east-2:004805068978:textract_task_completion"}}', 'url': 'https://textract.us-east-2.amazonaws.com/', 'context': {'client_region': 'us-east-2', 'client_config': <botocore.config.Config object at 0x10c4d4b50>, 'has_streaming_input': False, 'auth_type': None}} 2020-04-09 15:40:28,121 botocore.hooks [DEBUG] Event request-created.textract.StartDocumentTextDetection: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x10c4d4ad0>> 2020-04-09 15:40:28,121 botocore.hooks [DEBUG] Event choose-signer.textract.StartDocumentTextDetection: calling handler <function set_operation_specific_signer at 0x10a33e320> 2020-04-09 15:40:28,122 botocore.auth [DEBUG] Calculating signature using v4 auth. 2020-04-09 15:40:28,122 botocore.auth [DEBUG] CanonicalRequest: POST/ content-type:application/x-amz-json-1.1 host:textract.us-east-2.amazonaws.com x-amz-date:20200409T224028Z x-amz-target:Textract.StartDocumentTextDetection content-type;host;x-amz-date;x-amz-target 3a1a7274e3f710907df62435ea1e8886c83bf00ffa5fb29e7fe62e8ce8d3aab4 2020-04-09 15:40:28,122 botocore.auth [DEBUG] StringToSign: AWS4-HMAC-SHA256 20200409T224028Z 20200409/us-east-2/textract/aws4_request b6ee2e816a57749ee3685aa1ec527ab5c5942fa6a47a85cca131c5d1feb6603c 2020-04-09 15:40:28,122 botocore.auth [DEBUG] Signature: 9609cbbb18487bbdd9112f85cd14c44cd79d75074af449c558cf194947454df7 2020-04-09 15:40:28,122 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://textract.us-east-2.amazonaws.com/, headers={'X-Amz-Target': b'Textract.StartDocumentTextDetection', 'Content-Type': b'application/x-amz-json-1.1', 'User-Agent': b'Boto3/1.12.35 Python/3.7.7 Darwin/18.7.0 Botocore/1.15.35', 'X-Amz-Date': b'20200409T224028Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=AKIAIUNZ7IPRD2VWHCRQ/20200409/us-east-2/textract/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=9609cbbb18487bbdd9112f85cd14c44cd79d75074af449c558cf194947454df7', 'Content-Length': '275'}> 2020-04-09 15:40:28,122 urllib3.connectionpool [DEBUG] Starting new HTTPS connection (1): textract.us-east-2.amazonaws.com:443 2020-04-09 15:40:28,609 urllib3.connectionpool [DEBUG] https://textract.us-east-2.amazonaws.com:443 "POST / HTTP/1.1" 400 81 2020-04-09 15:40:28,609 botocore.parsers [DEBUG] Response headers: {'Date': 'Thu, 09 Apr 2020 22:40:28 GMT', 'Content-Type': 'application/x-amz-json-1.1', 'Content-Length': '81', 'Connection': 'keep-alive', 'x-amzn-RequestId': '3462d30a-7b69-40e4-b392-0bfb1a5b08f8'} 2020-04-09 15:40:28,609 botocore.parsers [DEBUG] Response body: b'{"__type":"InvalidParameterException","Message":"Request has invalid parameters"}' 2020-04-09 15:40:28,610 botocore.hooks [DEBUG] Event needs-retry.textract.StartDocumentTextDetection: calling handler <botocore.retryhandler.RetryHandler object at 0x10c4d4f10> 2020-04-09 15:40:28,610 botocore.retryhandler [DEBUG] No retry needed. Traceback (most recent call last): File "/Users/prashanthayyavu/repo/personal/pdf_to_els/src/notification_issue.py", line 19, in 'SNSTopicArn': snsTopicArn} File "/Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call return self._make_api_call(operation_name, kwargs) File "/Users/prashanthayyavu/opt/anaconda3/envs/pdf_to_els/lib/python3.7/site-packages/botocore/client.py", line 626, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the StartDocumentTextDetection operation: Request has invalid parameters

Process finished with exit code 1

swetashre commented 4 years ago

@prashanthayyavu - Thank you for your response. Code looks fine to me but i have some concerned about the sns topic. Does textract has permission to access the SNS topic ? https://docs.aws.amazon.com/textract/latest/dg/api-async-roles.html

no-response[bot] commented 4 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

jeguiguren-cohere commented 1 year ago

Hello @swetashre I just ran into the same issue. I noticed that there may be a limit on JobTag string length.

Debug logs show nothing besides the error Error running aws textract: An error occurred (InvalidParameterException) when calling the StartDocumentTextDetection operation: Request has invalid parameters

But I noticed that a JobTag < 65 characters works, and anything longer than that fails.

Is this a constraint on the parameter, and can we add to the docs if so?

Update: Never mind, I see it in the API docs https://docs.aws.amazon.com/textract/latest/dg/API_StartDocumentAnalysis.html#API_StartDocumentAnalysis_RequestSyntax

Thank you!

avijit1258 commented 8 months ago

Hello @swetashre I just ran into the same issue. I noticed that there may be a limit on JobTag string length.

Debug logs show nothing besides the error Error running aws textract: An error occurred (InvalidParameterException) when calling the StartDocumentTextDetection operation: Request has invalid parameters

But I noticed that a JobTag < 65 characters works, and anything longer than that fails.

Is this a constraint on the parameter, and can we add to the docs if so?

Update: Never mind, I see it in the API docs https://docs.aws.amazon.com/textract/latest/dg/API_StartDocumentAnalysis.html#API_StartDocumentAnalysis_RequestSyntax

Thank you!

thanks for your comment, saved my day. I had Textract Go SDK shouting InvalidParameterException and the issue was JobTag length and some not allowed character.