我正在使用js npm库aws-sdk查询AWS对象。
从同一脚本中,它可以使用ec2.describeInstances检索ec2实例详细信息,但是每次我得到route53Domains.listDomains()
时,它都会执行:
UnknownError:错误的网关
我正在从执行此脚本的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()
答案 0 :(得分:0)
根据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”地区。