at present I am doing a lambda function in node.js to get information of my AWS account. I have an issue when I want to retrieve the information required in the function. I see the information in the console (console.log) but it is not present in the response by callback(). I always get response of first callback and not of second. I have read about the asynchronous process but I don't achieve fix the issue. Do you know what is the change to improve the code?
The code is the next:
var AWS = require('aws-sdk');
var iam = new AWS.IAM();
var s3 = new AWS.S3();
exports.handler = (event, context, callback) => {
var params1 = {};
iam.listUsers(params1, function(err, data) {
if (err)
console.log(err, err.stack);
else
console.log(data);
callback(null, data.Users);
});
var params2 = {};
s3.listBuckets(params2, function(err, data) {
if (err)
console.log(err, err.stack);
else
console.log(data);
callback(null, data.Buckets);
});
};
Thanks in advance.