laurent
laurent

Reputation: 90863

How to prevent an AWS lambda function from running more than once simultaneously?

I've got a lambda function and I would like to make sure that it's never being called a second time if it's already running. Is there any option to force this behavior?

Upvotes: 6

Views: 4500

Answers (4)

Nhu Trinh
Nhu Trinh

Reputation: 13986

2021: Lambda now support concurrency setting. Change the reserve concurrency setting to 1 for this

Upvotes: 5

Ankur Shrivastava
Ankur Shrivastava

Reputation: 243

I just did a workaround by copying file to transient bucket and put an if condition In case any other Lambda triggers It will come out due to if condition

Upvotes: 0

imTachu
imTachu

Reputation: 3809

AWS Lambda FAQ says that the service is designed to run functions in parallel.

FAQ

However, you could manage this from your application if you are using the microservice-http-endpoint blueprint. You can do it since this kind of blueprint is just a web service that you can call somewhere.

Upvotes: 2

Mark B
Mark B

Reputation: 201088

AWS Lambda currently doesn't support this behavior. You could try using DynamoDB to create a lock, but that's obviously not the most ideal scenario. Right now this use case isn't a very good fit for Lambda.

I have a job that I need to ensure only one is ever running, and I wasn't happy with any Lambda solution for that. I ended up just running it on a t2.nano instance.

Upvotes: 3

Related Questions