Is it possible to kill/stop a running lambda function?

0

I want to make sure that only one instance of a lambda function is running at a given time, so that if a new container begins to run if any other is already running should be stopped/killed. Is it possible?

Edited by: hzelaya on Mar 24, 2017 1:49 PM

hzelaya
asked 6 years ago822 views
5 Answers
0

+1

I would love to list and possibly kill running functions.

Tamas

Tamas
answered 5 years ago
0

That's not what we should use lambda for

Ideally each lambda function should be only one function. A real one function of the programming language. Which not loop or even have state. And it should be able to run in parallel. This is functional paradigm

If you need to have state, use step function to call lambda. Even you just need to loop for pulling task but if it can take times longer than 1 minute you should use step function. All lambda function should be able to let itself die in 1 minute and so you could maintain that it will have only one of it alive in each minute

If you really need to ensure that it must have only one of it in each minute. You could use dynamodb or any other state keeper as a mutex, to let every lambda check that should it end itself when the mutex id was changed. Not that it will always have one lambda but it let old lambda kill itself when it know it not needed

answered 5 years ago
0

I don't think you fully understand what the question is about, or how AWS Lambda works.

Lambda will create containers when a function is invoked, with automatic load-based scaling that is fully transparent to the user. These containers can stay running for a while when requests are coming in, but they will be killed eventually - in particular when there is no load.

To avoid long execution times or excessive cost due to API requests, it sometimes makes sense to cache resources on startup and reuse them while a Lambda container is running.
This can lead to issues when those resources become invalidated. In such a case, it would be very useful to have a way to kill all running containers of a function.
The alternative would be to manage lifetime of cached resources inside the function, but this seems a bit heavy-handed.

answered 3 years ago
0

Not to mention, they allow Async versions of them to run up to 6 hours now. There should be a way to monitor them and stop them if needed. e.g. a function that produces a report by going through a lot of data, could take a while to run. If "stuck" should be able to be killed.

Rahly
answered 3 years ago
0

The current maximum runtime for a lambda invocation is 15 minutes, not 6 hours. The 6 hours is the default maximum age of a single async request before it won't be retried anymore. There is no defined lifetime for a lambda container.

Regarding container reuse, if you're caching something in your lambda, it either needs to be never changing or you need to handle the cache invalidation yourself. You can work around this by bumping the version on the lambda and using the new version, which will avoid using the old version containers, but that's a bit of a hacky solution.

Ellison
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions