简体   繁体   English

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

[英]AWS API Gateway JS SDK get HTTP response code

I am using the generated JS SDK by API Gateway. 我正在使用API​​ Gateway生成的JS SDK。 Problem is when theres errors, I get a CORS error and I am unable to get the data inside nor the status code: 问题是当出现错误时,出现CORS错误,并且无法获取内部数据或状态代码:

在此处输入图片说明

Notice data is "" despite there being a message in the network tab 尽管“网络”标签中显示一条消息,但通知数据仍为“”

在此处输入图片说明

My code: 我的代码:

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)
    })

try to pass the region too... so inside: 尝试也通过该区域...所以里面:

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

because by default it uses 'us-east-1' if you don't pass it 因为默认情况下,如果您不通过它,则使用“ us-east-1”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM