【问题标题】:AWS js aws-sdk route53Domains.listDomains() returns "UnknownError: Bad Gateway"AWS js aws-sdk route53Domains.listDomains() 返回“UnknownError:Bad Gateway”
【发布时间】:2019-05-01 05:31:51
【问题描述】:

我正在使用 js npm 库 aws-sdk 来查询 AWS 对象。

在同一个脚本中,它能够使用 ec2.describeInstances 检索 ec2 实例详细信息,但是当它每次执行 route53Domains.listDomains() 时:

UnknownError: Bad Gateway

我正在使用来自执行此脚本的 ec2 实例的 ec2 实例身份验证,因此我没有设置任何 api 密钥。

如果没有配置代理,则根本无法调用。

const AWS = require('aws-sdk')
const proxy = require('proxy-agent')
const Logger = require('logplease')

const logOptions = {
  useColors: false // Disable colors
}

const myLogger = Logger.create('testAws', logOptions)
Logger.setLogLevel('DEBUG')

AWS.config.update({
  httpOptions: { agent: proxy('http://my.proxy.here:8080') },
  region: 'ap-southeast-2', // ec2 client needs this
  logger: myLogger
})

myLogger.log('testAws Starting')

myLogger.log('About to create ec2 client')
const ec2 = new AWS.EC2()
myLogger.log('ec2 client created')

myLogger.log('About to create route53Domainsclient')
const route53Domains = new AWS.Route53Domains()
myLogger.log('route53Domainsclient created')

function listDomains() {
  return new Promise(async (resolve, reject) => {
    try {
      myLogger.log('About to listDomains')
      const rsp = await route53Domains.listDomains({}).promise()
      myLogger.log(`Domains listed: ${JSON.stringify(rsp, null, 2)}`)
      resolve()
    } catch (err) {
      myLogger.error(`Error listDomains: ${err}`)
      reject(err)
    }
  })
}
function describeInstances() {
  return new Promise(async (resolve, reject) => {
    try {
      myLogger.log('About to describeInstances')
      const params = {}
      const response = await ec2.describeInstances(params).promise()
      myLogger.log(`Successfully describeInstances: output: ${JSON.stringify(response, null, 2)}`)
      resolve()
    } catch (err) {
      myLogger.error(`Error describeInstances: ${err}`)
      reject(err)
    }
  })
}

async function doInstanceOps() {
  return new Promise(async (resolve) => {
    try {
      await describeInstances()
    } catch (err) {
      myLogger.log('error in describeInstances()')
    }
    myLogger.log('doInstanceOps complete')
    resolve()
  })
}

async function doRoute53Ops() {
  return new Promise(async (resolve) => {
    try {
      await listDomains()
    } catch (err) {
      myLogger.error('error in doRoute53Ops()')
    }
    myLogger.log('doRoute53Ops complete')
    resolve()
  })
}

async function doEverything() {
  myLogger.log('doEverything Starting')

  await doInstanceOps()
  await doRoute53Ops()
  myLogger.log('doEverything Finished')
}

doEverything()
2018-11-29T07:47:47.158Z [DEBUG] testAws: testAws Starting
2018-11-29T07:47:47.160Z [DEBUG] testAws: About to create ec2 client
2018-11-29T07:47:47.189Z [DEBUG] testAws: ec2 client created
2018-11-29T07:47:47.189Z [DEBUG] testAws: About to create route53Domainsclient
2018-11-29T07:47:47.191Z [DEBUG] testAws: route53Domainsclient created
2018-11-29T07:47:47.192Z [DEBUG] testAws: doEverything Starting
2018-11-29T07:47:47.192Z [DEBUG] testAws: About to describeInstances
2018-11-29T07:47:47.493Z [DEBUG] testAws: [AWS ec2 200 0.299s 0 retries] describeInstances({})
2018-11-29T07:47:47.494Z [DEBUG] testAws: Successfully describeInstances: 
output: {
  "Reservations": [
    {
      "Groups": [],
      "Instances": [
        {
          "AmiLaunchIndex": 0,
          "ImageId": 
< I have removed a massive payload here as it has internal details >
2018-11-29T07:23:02.654Z [DEBUG] testAws: doInstanceOps complete
2018-11-29T07:23:02.654Z [DEBUG] testAws: About to listDomains
2018-11-29T07:23:03.272Z [DEBUG] testAws: [AWS route53domains 502 0.617s 3 retries] listDomains({})
2018-11-29T07:23:03.273Z [ERROR] testAws: Error listDomains: UnknownError: Bad Gateway
2018-11-29T07:23:03.273Z [ERROR] testAws: error in doRoute53Ops()
2018-11-29T07:23:03.273Z [DEBUG] testAws: doRoute53Ops complete
2018-11-29T07:23:03.273Z [DEBUG] testAws: doEverything Finished

我的 npm 版本是:

C:\testApp\testApp-api>npm list aws-sdk
testApp-api@1.0.0 C:\testApp\testApp-api
+-- aws-sdk@2.364.0
`-- credstash@1.0.44
  `-- aws-sdk@2.2.35

C:\testApp\testApp-api>npm list proxy-agent
testApp-api@1.0.0 C:\testApp\testApp-api
`-- proxy-agent@3.0.3

C:\testApp\testApp-api>npm list logplease
testApp-api@1.0.0 C:\testApp\testApp-api
`-- logplease@1.2.15

我刚刚测试了从 AWS.config 中注释掉的 http 代理配置,如下所示:

AWS.config.update({
  // httpOptions: { agent: proxy('http://myproxy.here:8080') },
  region: 'ap-southeast-2', // ec2 client needs this
  logger: myLogger
})

我得到了这个错误:

2018-11-29T08:30:02.192Z [DEBUG] testAws: About to listDomains
2018-11-29T08:30:02.465Z [DEBUG] testAws: [AWS route53domains undefined 0.271s 3 retries] listDomains({})
2018-11-29T08:30:02.465Z [ERROR] testAws: Error listDomains: UnknownEndpoint: Inaccessible host: `route53domains.ap-southeast-2.amazonaws.com'. This service may not be available in the `ap-southeast-2' region.
2018-11-29T08:30:02.465Z [ERROR] testAws: error in doRoute53Ops()

【问题讨论】:

  • 认真的吗?一点都不吃,这是node.js,aws和java script,听说这些是流行的技术,我不能是唯一一个使用它的人:)

标签: javascript amazon-web-services amazon-ec2 aws-sdk-js


【解决方案1】:

根据 AWS 支持人员的建议,我将区域从“ap-southeast-2”更改为“us-east-1”,对于 route53domains 调用,这解决了问题。

有关更多信息,请参阅此link,它适用于 Java SDK,但我听说它也适用于其他 SDK。

请参阅AWS Regions and Endpoints page 上的“Amazon Route 53”,它表明此 API 服务 (route53domains) 仅在单个区域“us-east-1”中可用,因此所有对全球 route53domains 的 aws-sdk 调用都需要转到“us-east-1”区域。

【讨论】:

    猜你喜欢
    • 2016-02-29
    • 2016-02-10
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2019-09-15
    • 2015-10-15
    相关资源
    最近更新 更多