未从 Textract 接收到 Amazon SNS 的消息

时间:2021-02-08 21:29:22

标签: amazon-web-services amazon-sqs amazon-sns amazon-textract

我正在使用 Amazon TextractStartDocumentAnalysis 函数从 S3 存储桶异步扫描 .pdf 文件。正如文档所说,我应该会收到有关所提供 SNS 主题的作业状态的通知。

<块引用>

StartDocumentAnalysis 返回用于获取操作结果的作业标识符 (JobId)。文本分析完成后,Amazon Textract 会向您在 NotificationChannel 中指定的 Amazon Simple Notification Service (Amazon SNS) 主题发布完成状态。

我用来开始分析的代码如下所示:

    fun analyzeDocument(documentId: String) {
        klogger.info { "Start Textract analysis on document '$documentId'" }

        val request = StartDocumentAnalysisRequest()
            .withFeatureTypes("TABLES", "FORMS")
            .withDocumentLocation(DocumentLocation()
                .withS3Object(S3Object()
                    .withName(documentId)
                    .withBucket(bucketName)
                )
            )
            .withNotificationChannel(NotificationChannel()
                .withSNSTopicArn(snsTopicArn)
                .withRoleArn(snsRoleArn)
            )

        val jobId = textract.startDocumentAnalysis(request).jobId

        klogger.info { "Analysis started for document '$documentId'. Job ID: '$jobId'" }
    }

我已在 AWS 控制台中创建了 SNS。

  • snsTopicArn = arn:aws:sns:us-east-1:093475263507:textract-result.fifo
  • snsRoleArn = arn:aws:iam::093475263507:role/SNSSuccessFeedback

我能够从控制台手动向该 SNS 发布消息,但没有来自 Textract 的消息进入 SNS 主题。我已经等了几个小时了 - 我怀疑现在我应该已经收到消息了。

我不确定 snsRoleArn 是否正确。我只是使用了一些我在 AWS 中已有的随机方法。这可能是个问题吗?我应该使用哪个 snsRoleArn?如果不是这样,为什么我没有收到消息?

我是否会遗漏访问政策中的某些内容?

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__default_statement_ID",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": [
        "SNS:GetTopicAttributes",
        "SNS:SetTopicAttributes",
        "SNS:AddPermission",
        "SNS:RemovePermission",
        "SNS:DeleteTopic",
        "SNS:Subscribe",
        "SNS:ListSubscriptionsByTopic",
        "SNS:Publish",
        "SNS:Receive"
      ],
      "Resource": "arn:aws:sns:us-east-1:093475263507:textract-result.fifo",
      "Condition": {
        "StringEquals": {
          "AWS:SourceOwner": "093475263507"
        }
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

为特定任务使用随机 IAM 角色不是最佳实践。对于此用例,您应该使用附加了 SN​​S 策略的 IAM 角色。我会尝试使用这样的东西:

enter image description here