我有一个 .Net core 客户端应用程序,根据 AWS 文档,使用带有 S3、SNS 和 SQS 的 amazon Textract 检测和分析多页文档中的文本(https://docs.aws.amazon.com/texttract/latest/dg/async.html https://docs.aws.amazon.com/textract/latest/dg/async.html)
使用 AmazonTextractServiceRole 策略创建 AWS 角色,并根据文档添加以下信任关系 (https://docs.aws.amazon.com/texttract/latest/dg/api-async-roles.html https://docs.aws.amazon.com/textract/latest/dg/api-async-roles.html)
{
"版本": "2012-10-17",
“陈述”: [
{
"效果": "允许",
“主要的”: {
“服务”:“texttract.amazonaws.com”
},
“行动”:“sts:假设角色”
}
]
}
订阅 SQS 主题并授予 Amazon SNS 主题按照 aws 文档将消息发送到 Amazon SQS 队列的权限。
所有资源包括S3 Bucket,SNS,SQS都在同一个us-west2区域
以下方法显示一般错误“InvalidParameterException”
请求包含无效参数
但如果NotificationChannel 部分被注释,则代码工作正常并返回正确的作业ID。
错误消息没有给出有关参数的清晰图片。高度赞赏任何帮助。
public async Task<string> ScanDocument()
{
string roleArn = "aws:iam::xxxxxxxxxxxx:instance-profile/MyTextractRole";
string topicArn = "aws:sns:us-west-2:xxxxxxxxxxxx:AmazonTextract-My-Topic";
string bucketName = "mybucket";
string filename = "mytestdoc.pdf";
var request = new StartDocumentAnalysisRequest();
var notificationChannel = new NotificationChannel();
notificationChannel.RoleArn = roleArn;
notificationChannel.SNSTopicArn = topicArn;
var s3Object = new S3Object
{
Bucket = bucketName,
Name = filename
};
request.DocumentLocation = new DocumentLocation
{
S3Object = s3Object
};
request.FeatureTypes = new List<string>() { "TABLES", "FORMS" };
request.NotificationChannel = channel; /* Commenting this line work the code*/
var response = await this._textractService.StartDocumentAnalysisAsync(request);
return response.JobId;
}