AWS API Gateway JS SDK获取HTTP响应代码

时间:2017-05-27 13:02:43

标签: javascript amazon-web-services aws-api-gateway

我正在使用API​​ Gateway生成的JS SDK。问题是当出现错误时,我收到CORS错误,我无法获取内部数据或状态代码:

enter image description here

尽管网络标签中有消息

,但通知数据仍为“”

enter image description here

我的代码:

AWS.config.region = "ap-northeast-2"
const cognitoParams = {
  IdentityPoolId: "ap-northeast-2:...",
  Logins: {
    "accounts.google.com": googleUser.getAuthResponse().id_token
  }
}

AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams)

AWS.config.credentials.get(function () {

  const api = apigClientFactory.newClient({
    accessKey: AWS.config.credentials.accessKeyId,
    secretKey: AWS.config.credentials.secretAccessKey,
    sessionToken: AWS.config.credentials.sessionToken
  })
  api.ec2Get()
    .then(function (data) {
      console.log('data', data);
    })
    .catch(function (err) {
      console.error('err', err)
    })

1 个答案:

答案 0 :(得分:1)

尝试传递该区域......所以内部:

const api = apigClientFactory.newClient({
  accessKey: AWS.config.credentials.accessKeyId,
  secretKey: AWS.config.credentials.secretAccessKey,
  sessionToken: AWS.config.credentials.sessionToken,
  region: '...'
})

因为默认情况下它使用的是“us-east-1'如果你没有通过它