我在Lambda中运行以下代码,该代码由包含CreateAccount函数的状态ID的SNS消息触发。在本地运行时,它工作正常,但是在Lambda中触发时,CloudWatch日志不显示任何内容。
var AWS = require("aws-sdk");
var sns = new AWS.SNS();
var organizations = new AWS.Organizations({region: 'us-east-1'});
exports.handler = (event, context, callback) => {
var message = event.Records[0].Sns.Message;
console.log("From sns:", message);
var obj = JSON.parse(message);
var name = obj.name;
console.log("Name :", obj.name);
var email = obj.email;
console.log("Email :", obj.email);
var budget = obj.budget;
console.log("Budget :", obj.budget);
var awsaccount = obj.awsaccount;
console.log("Account Name :", obj.awsaccount);
var adminaccount = obj.adminaccount;
console.log("Admin account name :", obj.adminaccount);
var adminpassword = obj.adminpassword;
console.log("Admin password :", obj.adminpassword);
var accStatusId = obj.statusid;
//var accStatusId = (accStatusId.replace(/\"/g, ""));
console.log("Status ID :", obj.statusid);
context.succeed(message);
// Fetch status of account creation and account ID
var AccStatusParams = {
CreateAccountRequestId: accStatusId
};
checkStatus(AccStatusParams);
};
function checkStatus(AccStatusParams){
organizations.describeCreateAccountStatus(AccStatusParams, function(err, data) {
if (err) console.log(err, err.stack);
else { console.log(data);
console.log("Account = ", JSON.stringify(data.CreateAccountStatus.AccountId));
console.log("Status = ", JSON.stringify(data.CreateAccountStatus.State));
}
});
}