Deepak
Deepak

Reputation: 746

execute aws lambda function sequentially

I have written a python script for autoscaling server naming. which will check current servers in autoscaling and give an appropriate name and sequence to the new server.

I am triggering my Aws lambda function by autoscaling event. and when I bring 3 servers at the same time(or new autoscaling with desired capacity 10) I don't want lambda to be executed parallelly. it is making my script assign the same count for all servers.

Or if I can implement some kind of locking to put other lambdas in wait state. So what should i used for it.

Upvotes: 1

Views: 1989

Answers (1)

Yeshodhan Kulkarni
Yeshodhan Kulkarni

Reputation: 2943

There are 2 options:

  1. You can create a distributed lock using a DynamoDB table. This will help you maintain a state saying Operation in progress. Every time a lambda function is invoked due to an autoscaling event, you can check if this record exists in dynamodb. If it does not create one, and proceed. If it exists, do nothing and return. After your lambda function executes successfully, remove this entry. This probably will add not more than $2.00 to your total AWS bill as the read and write capacity for this table will be really low.
  2. You can make use of the step functions to implement this scenario. With step functions you can check if one is already running and skip.

    Read more about step functions here: https://aws.amazon.com/step-functions/

Upvotes: 2

Related Questions