The lamda statement is querying DynamoDB, emailing customers with info and then updating the database. However, I need this to happen not in parallel, so each request is placed in a queue, as the database update may affect the next customers query. Any thoughts? I’m using Python for the lambda.
Ah thank you! How does this work if the queue for the lambda increases, will requests get dropped of the queue gets too large?
it will report an error to the caller. i think there is some minor queuing going on, and many services do limited number of retries (like sns). but you should not rely on any of it. you will need to insert a queue between the event source and the lambda, for example sqs.
Why not use SQS and only process one message at a time?
Awesome, thank you.
You could just start one lambda and wait on the callback each step of the way. This code is missing all the parameters, but it gives the general idea.
var dynamodb = new AWS.DynamoDB();
var ses = new AWS.SESV2();
dynamodb.getItem(params, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
ses.sendEmail(params, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
dynamodb.putItem(params, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
context.succeed()
}
});
}
});
}
});
You could also turn this into a function, fill an array with requests and have the function recursively call itself until you’ve been trough the entire array.
Definitely a job for an ordered queue to handle, like SQS. Use your Lambda functions as workers picking up off the queue doing what you describe. Just be cautious of retried messages.
Since you’re using Python, give this a shot: https://pypi.org/project/sqs-workers/
Use AWS Step Function. This is exactly why they have been created.
Why can’t you just wait for every operation in your lambda function? Seems pretty standard to me. If you use promises it’s super simple.