sparse-intern-71089
05/07/2019, 12:22 AMtall-librarian-49374
05/07/2019, 6:53 AMasync
function, smth like:
callback: async event => {
const s3 = new aws.sdk.S3({ apiVersion: "2006-03-01" });
const foo = await s3.listBuckets().promise();
console.log(foo.Buckets);
}
white-balloon-205
async
function, then you can use the callback form of the AWS API calls. For example:
const ingestFunction = new aws.lambda.CallbackFunction("processor", {
role: lambdaRole,
callback: (event, context, callback) => {
const s3 = new aws.sdk.S3({ apiVersion: "2006-03-01" });
const foo = s3.listBuckets((err, data) => {
callback(err, data);
});
console.log(foo);
}
});
But in general, using the promise/async version is likely going to be simpler.
AWS Lambda decides whether to wait for the callback
to be called based on whether the function returns a promise or not - so as soon as you make it async
(meaning it will return a Promise), it will not wait for the callback
and will instead return as soon as the promise resolves, which will happen immediately without waiting for your listBuckets
call to complete.proud-tiger-5743
05/07/2019, 5:11 PM