【问题标题】:AWS4 signature in Node.jsNode.js 中的 AWS4 签名
【发布时间】:2018-10-10 17:26:29
【问题描述】:

我正在尝试使用 aws4 包通过 Javascript 调用私有 Amazon API,但无法正常工作。我可以使用 Postman 成功拨打电话,但我试图让它与代码一起使用,但我失败了。

这是邮递员截图:

下面是试图复制它的代码:

request(aws4.sign({
    service: 'execute-api',
    region: 'us-east-1',
    method: 'POST',
    url: 'https://test.amazonAPI.com/test/doThing',
    body: load
  },
  {
    accessKeyId: tempCreds.Credentials.AccessKeyId,
    secretAccessKey: tempCreds.Credentials.SecretAccessKey,
    sessionToken: tempCreds.Credentials.SessionToken
  }))

我目前遇到的错误:

Error: getaddrinfo ENOTFOUND execute-api.us-east-1.amazonaws.com execute-api.us-east-1.amazonaws.com:443
    at errnoException (dns.js:53:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:95:26)

【问题讨论】:

  • 如果需要也可以看github.com/DavidMuller/aws-requests-auth
  • aws4 模块在这方面似乎有点死板。目前尚不清楚(粗略一瞥)它是否具有使用 API 网关 URL 所需的灵活性。

标签: node.js amazon-web-services aws-sdk-js


【解决方案1】:

我认为您在 requestOptions 中缺少 主机名。 正确:

request(aws4.sign({
    hostname: 'test.amazonAPI.com',
    service: 'execute-api',
    region: 'us-east-1',
    method: 'POST',
    url: 'https://test.amazonAPI.com/test/doThing', // this field is not recommended in the document.
    body: load
  },
  {
    accessKeyId: tempCreds.Credentials.AccessKeyId,
    secretAccessKey: tempCreds.Credentials.SecretAccessKey,
    sessionToken: tempCreds.Credentials.SessionToken
  }))

参考:https://github.com/mhart/aws4

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2019-12-04
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    相关资源
    最近更新 更多