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
질문됨 7년 전4762회 조회
5개 답변
0

+1

I would love to list and possibly kill running functions.

Tamas

Tamas
답변함 6년 전
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

답변함 6년 전
profile picture
전문가
검토됨 22일 전
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.

답변함 4년 전
profile picture
전문가
검토됨 22일 전
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
답변함 4년 전
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
답변함 4년 전
profile picture
전문가
검토됨 22일 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠