AWSLex GetSlotType API。提取最新版本的SlotType时出错

时间:2018-08-09 05:54:00

标签: amazon-web-services amazon-lex

我是AWSLex的新手。我试图通过ModelBuilding GetSlotType API获取SlotType信息。 请求网址:GET / slottypes / name / versions / version HTTP / 1.1 要获取每个文档的最新版本,请使用Pattern:\ $ LATEST | [0-9] +

通过Postman我可以执行版本号,但是在获取最新版本$ LATEST时,我使用的URL是 https://models.lex.us-east-1.amazonaws.com/slottypes/serviceType/versions/%24LATEST 通过Postman可以很好地工作。

我用来创建签名的URL无效。我收到以下错误

我们计算出的请求签名与您提供的签名不匹配。检查您的AWS秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。

我生成的规范请求如下

   GET
   /slottypes/serviceType/versions/%24LATEST

   content-type:application/json
   host:models.lex.us-east-1.amazonaws.com
   x-amz-date:20180809T052553Z

   content-type;host;x-amz-date
   e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

非常感谢您提供有关解决此问题的帮助。

 String payloadHash = CommonUtil.hexEncode(sha256Hash(payload));
 ZonedDateTime utcNow = Instant.now().atZone(ZoneOffset.UTC);// Date 
 for headers and the credential string
 String amzDate = 
 utcNow.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
  String dateStamp = 
  utcNow.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
 String canonicalHeaders = String.format("content-type:%s\nhost:%s\nx- 
  amz-date:%s\n", contentType, host, amzDate);
 String canonicalRequest = String.format("%s\n%s\n%s\n%s\n%s\n%s", 
 method, canonicalUri, canonicalQueryString, canonicalHeaders, 
 signedHeaders, payloadHash);
  String credentialScope = String.format("%s/%s/%s/aws4_request", 
  dateStamp, region, service);
  String canonicalRequestHash = 
   CommonUtil.hexEncode(sha256Hash(canonicalRequest));
   String stringToSign = String.format("%s\n%s\n%s\n%s", algorithm, 
   amzDate, credentialScope, canonicalRequestHash);
  byte[] signatureKey = CommonUtil.getSignatureKey(secretKey, 
   dateStamp, region, service);
  String signature = CommonUtil.hexEncode(CommonUtil.HmacSHA256(URLEncoder.encode(stringToSign,"utf-8"), signatureKey));
   String authorizationHeader = String.format("%s Credential=%s/%s, SignedHeaders=%s, Signature=%s", algorithm, accessKey, credentialScope, signedHeaders, signature);

MultivaluedMap<String, String> headersMap = new MultivaluedHashMap<>();
headersMap.add("Content-Type", contentType);
headersMap.add("X-Amz-Date", amzDate);
headersMap.add("Authorization", authorizationHeader);

这就是我生成签名的方式。相同的代码在版本号上可以正常工作。问题出在我用$ LATEST作为值编码URL并将其传递时。

0 个答案:

没有答案