简体   繁体   中英

AWS API Gateway JS SDK get HTTP response code

I am using the generated JS SDK by API Gateway. Problem is when theres errors, I get a CORS error and I am unable to get the data inside nor the status code:

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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