我一直试图通过RDS中的Lambda检索RDS实例的状态,但由于无法解析响应,所以我一直很简短。我知道我在这里完全缺少明显的东西。这是代码:
var AWS = require('aws-sdk');
var rdsparams = {
DBInstanceIdentifier: 'mysql1'
};
module.exports = (instanceId) => {
var rds = new AWS.RDS();
var params = {
DBInstanceIdentifier: instanceId
};
var rdsResponse = rds.describeDBInstances(rdsparams, function (err,
data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
var resultData = {};
rds.describeDBInstances(rdsparams, function(err, data) {
if (err)
return context.done(err, null);
var rdsarray = {};
var rdsarray = (data);
console.log(rdsarray);
var ins = rdsarray[0];
console.log("Status: " + ins.DBInstanceStatus);
});
};
答案 0 :(得分:2)
您的代码在那里发生了很多事情!
具体的问题是data
不是数组。在这里查看文档的响应:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/RDS.html#describeDBInstances-property
返回值的数组在data.DBInstances
中。所以最后几行可能是:
var rdsarray = data.DBInstances;
console.log(rdsarray);
var ins = rdsarray[0];
console.log("Status: " + ins.DBInstanceStatus);