gpt4 book ai didi

amazon-web-services - AWS Textract StartDocumentAnalysis 函数未向 SNS 主题发布消息

转载 作者:行者123 更新时间:2023-12-01 00:12:29 24 4
gpt4 key购买 nike

我正在使用 AWS Textract 并且我想分析一个多页文档,因此我必须使用异步选项,所以我首先使用了 startDocumentAnalysis函数,我得到了一个 JobId 作为返回,但它需要触发一个我设置为在 SNS 主题收到消息时触发的函数。

这些是我的无服务器文件和处理程序文件。

provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource: { "Fn::Join": ["", ["arn:aws:s3:::${self:custom.secrets.IMAGE_BUCKET_NAME}", "/*" ] ] }
- Effect: "Allow"
Action:
- "sts:AssumeRole"
- "SNS:Publish"
- "lambda:InvokeFunction"
- "textract:DetectDocumentText"
- "textract:AnalyzeDocument"
- "textract:StartDocumentAnalysis"
- "textract:GetDocumentAnalysis"
Resource: "*"

custom:
secrets: ${file(secrets.${opt:stage, self:provider.stage}.yml)}

functions:
routes:
handler: src/functions/routes/handler.run
events:
- s3:
bucket: ${self:custom.secrets.IMAGE_BUCKET_NAME}
event: s3:ObjectCreated:*

textract:
handler: src/functions/routes/handler.detectTextAnalysis
events:
- sns: "TextractTopic"

resources:
Resources:
TextractTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: "Start Textract API Response"
TopicName: TextractResponseTopic

处理程序.js
module.exports.run = async (event) => {
const uploadedBucket = event.Records[0].s3.bucket.name;
const uploadedObjetct = event.Records[0].s3.object.key;

var params = {
DocumentLocation: {
S3Object: {
Bucket: uploadedBucket,
Name: uploadedObjetct
}
},
FeatureTypes: [
"TABLES",
"FORMS"
],
NotificationChannel: {
RoleArn: 'arn:aws:iam::<accont-id>:role/qvalia-ocr-solution-dev-us-east-1-lambdaRole',
SNSTopicArn: 'arn:aws:sns:us-east-1:<accont-id>:TextractTopic'
}
};

let textractOutput = await new Promise((resolve, reject) => {
textract.startDocumentAnalysis(params, function(err, data) {
if (err) reject(err);
else resolve(data);
});
});
}

我手动向该主题发布了一条 sns 消息,然后它正在触发当前具有此功能的 textract lambda,
module.exports.detectTextAnalysis = async (event) => {
console.log('SNS Topic isssss Generated');
console.log(event.Records[0].Sns.Message);
};

我有什么错误,为什么 textract startDocumentAnalysis 没有发布消息并使其触发 lambda?

注意:在使用 startTextAnalysis 函数之前,我没有使用过 startDocumentTextDetection,尽管在此之前没有必要调用它。

最佳答案

确保您在信任关系中拥有您所使用的角色:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com",
"textract.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}

关于amazon-web-services - AWS Textract StartDocumentAnalysis 函数未向 SNS 主题发布消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56728521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com