我正在尝试根据其标签名称过滤ec2实例,但无法正常工作。我正在寻找带有以下标记的任何可用ec2实例:
var params = {
DryRun: false,
Filters: [
{
Name: "tag:Name",
Values: ["2test-dev-gh"],
},
{
Name: "tag:Enviro",
Values: ["devInstanceStatus"],
},
{
Key: "tag:Proj",
Value: ["dev-2test"],
},
{
Key: "tag:testServers",
Value: ["peekhours"]
}
]
};
当我使用第一个标签并注释掉其他标签时,此过滤器起作用,但是当我一起尝试所有标签时,会出现以下错误。
{
"errorType": "MultipleValidationErrors",
"errorMessage": "There were 4 validation errors:\n* UnexpectedParameter: Unexpected key 'Key' found in params.Filters[2]\n* UnexpectedParameter: Unexpected key 'Value' found in params.Filters[2]\n* UnexpectedParameter: Unexpected key 'Key' found in params.Filters[3]\n* UnexpectedParameter: Unexpected key 'Value' found in params.Filters[3]",
"trace": [
"MultipleValidationErrors: There were 4 validation errors:",
"* UnexpectedParameter: Unexpected key 'Key' found in params.Filters[2]",
"* UnexpectedParameter: Unexpected key 'Value' found in params.Filters[2]",
"* UnexpectedParameter: Unexpected key 'Key' found in params.Filters[3]",
"* UnexpectedParameter: Unexpected key 'Value' found in params.Filters[3]",
" at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:40:28)",
" at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:126:42)",
" at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)",
" at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:96:12)",
" at /var/runtime/node_modules/aws-sdk/lib/event_listeners.js:86:9",
" at finish (/var/runtime/node_modules/aws-sdk/lib/config.js:379:7)",
" at /var/runtime/node_modules/aws-sdk/lib/config.js:397:9",
" at EnvironmentCredentials.get (/var/runtime/node_modules/aws-sdk/lib/credentials.js:127:7)",
" at getAsyncCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:391:24)",
" at Config.getCredentials (/var/runtime/node_modules/aws-sdk/lib/config.js:411:9)"
]
}
这是我剩下的代码。
exports.handler = async function(event) {
const promise = new Promise(function(resolve, reject) {
const ec2 = new AWS.EC2();
ec2.describeInstances(params, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
})
});
return promise;
}
答案 0 :(得分:0)
您的参数应与以下结构匹配,请尝试以此替换参数。
var params = {
DryRun: false,
Filters: [
{
Name: "tag:Name",
Values: ["2test-dev-gh"],
},
{
Name: "tag:Enviro",
Values: ["devInstanceStatus"],
},
{
Name: "tag:Proj",
Values: ["dev-2test"],
},
{
Name: "tag:testServers",
Values: ["peekhours"]
}
]
};
原因是使用Key
而不是Name
和Value
而不是Values
。