Amazon web services AWS Textract InvalidParameterException
我有一个.Net核心客户端应用程序,根据AWS文档使用amazon Textract和S3、SNS和SQS,检测和分析多页文档中的文本() 使用AmazonExtractServiceRole策略创建了AWS角色,并根据文档()添加了以下信任关系 { “版本”:“2012-10-17”, “声明”:[ { “效果”:“允许”, “委托人”:{ “服务”:“textract.amazonaws.com” }, “操作”:“sts:假定角色” } ] } 根据aws文档,订阅主题的SQS并授予Amazon SNS主题向Amazon SQS队列发送消息的权限 包括S3桶、SNS、SQS在内的所有资源都位于同一个us-west2区域 以下方法显示一个一般错误“InvalidParameterException” 请求的参数无效 但是如果注释了NotificationChannel部分,则代码工作正常,并返回正确的作业id 错误消息没有给出有关参数的清晰图片。非常感谢您的帮助Amazon web services AWS Textract InvalidParameterException,amazon-web-services,.net-core,amazon-textract,Amazon Web Services,.net Core,Amazon Textract,我有一个.Net核心客户端应用程序,根据AWS文档使用amazon Textract和S3、SNS和SQS,检测和分析多页文档中的文本() 使用AmazonExtractServiceRole策略创建了AWS角色,并根据文档()添加了以下信任关系 { “版本”:“2012-10-17”, “声明”:[ { “效果”:“允许”, “委托人”:{ “服务”:“textract.amazonaws.com” }, “操作”:“sts:假定角色” } ] } 根据aws文档,订阅主题的SQS并授予Ama
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;
}
公共异步任务扫描文档()
{
字符串roleArn=“aws:iam::xxxxxxxxxxx:instance profile/MyTextractRole”;
string topicArn=“aws:sns:us-west-2:xxxxxxxxxxx:AmazonTextract My Topic”;
字符串bucketName=“mybucket”;
字符串filename=“mytestdoc.pdf”;
var请求=新的StartDocumentAnalysisRequest();
var notificationChannel=新notificationChannel();
notificationChannel.RoleArn=RoleArn;
notificationChannel.SNSTopicArn=主题图标;
var s3Object=新的s3Object
{
Bucket=bucketName,
Name=文件名
};
request.DocumentLocation=新的DocumentLocation
{
S3Object=S3Object
};
request.FeatureTypes=new List(){“TABLES”,“FORMS”};
request.NotificationChannel=channel;/*注释这行代码*/
var response=等待此消息。\u textractService.StartDocumentAnalysisAsync(请求);
return-response.JobId;
}
经过长时间的问题分析。我能解决它。。根据文档主题,仅需要向SQS发送消息操作。但在将其更改为所有SQS操作后,它开始工作。但AWS错误消息仍然会误导和混淆调试无效的AWS请求
在将请求对象分派到AWS服务器之前,AWS SDK会在本地验证请求对象。此验证将失败,出现不透明的错误,如OP
由于SDK是开源的,您可以检查源代码以帮助缩小无效参数的范围
在我们看代码之前:SDK(和文档)实际上是从描述API及其需求以及如何验证它们的特殊JSON文件生成的。实际代码是基于这些JSON文件生成的
我将以Node.js SDK为例,但我相信类似的方法也适用于其他SDK,包括.NET
在我们的例子中(AWS Textract),最新的Api版本是2018-06-27
。果然,JSON源文件在GitHub上
在我的例子中,实验将问题缩小到ClientRequestToken
。错误是不透明的InvalidParameterException
。我在SDK源JSON文件中搜索了它,果然是在:
“ClientRequestToken”:{
“类型”:“字符串”,
“最大”:64,
"min":1,,
“模式”:“^[a-zA-Z0-9-100;]+$”
},
一大堆未记录的需求 在我的例子中,我使用的令牌违反了正则表达式(
模式
,在上面的源代码中)。更改我的令牌代码以满足正则表达式解决了这个问题
对于这些不透明的类型错误,我建议使用这种方法。“一大堆未记录的需求!”这是非常正确的!