【问题标题】:InvalidParameterException when starting a Textract job using SNS Notification channel使用 SNS 通知通道启动 Textract 作业时出现 InvalidParameterException
【发布时间】:2021-09-29 18:15:19
【问题描述】:

当我启动一个文本文件 StartDocumentTextDetection 并尝试按如下方式设置 NotificationChannel

 response = client.start_document_text_detection(
        DocumentLocation={
            'S3Object': {
                'Bucket': s3BucketName,
                'Name': objectName
            },
        },
        ClientRequestToken='string',
        JobTag='string',
        NotificationChannel={
            'RoleArn': snsRoleArn,
            'SNSTopicArn': snsTopicArn
        }
    )

我得到一个 InvalidParameterException

调用 StartDocumentTextDetection 操作时发生错误(InvalidParameterException):Request has invalid parameters

python 3.7 boto3 1.12.35

【问题讨论】:

    标签: amazon-web-services amazon-textract


    【解决方案1】:

    我能够以最少的修改运行您的代码 sn-p,如下所示:

    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)
    

    从 Amazon Textract 到 SNS 主题的成功发布消息应该输出类似于:

    {'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}}
    

    以下是一些提示,以防其他人遇到此问题:

    • 确保为 SNSTopicArn 和 RoleArn 使用有效值
    • 如果要处理的文档位于 S3 文件夹中,则参数需要更改如下:

      DocumentLocation={
          'S3Object': {
              'Bucket': 's3BucketName',
              'Name': 'folder/documentName'
          }
      },
      

    希望这会有所帮助。

    【讨论】:

    • 对于任何偶然发现这一点的人,我的角色稍微不正确,而不是 'iam' 我有 'sts',因为它在我的凭据文件中。改成这个并且它起作用了: "RoleArn": "arn:aws:iam::xxxxx:role/developer-TF",
    【解决方案2】:

    我遇到了同样的问题,我删除了 JobTag。然后就解决了。

    # 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'
        }
    )
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2016-07-03
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多