Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill/terminate a running AWS Lambda function?

Tags:

I have a lambda function that runs over a period of ~10mins. Decently long for a Lambda but given our current needs/setup it's the simplest way for it to do what we need it to do.

However, a recent bug in our Lambda code made the lambda go haywire and basically DOS our own server. This is where I realized I have no idea how to kill this process if ever I need to (vs just wait for it to end/timeout). so...

Is there a way to do terminate a running lambda process from the AWS console? Is there a way to do it via AWS CLI?

like image 399
Jad S Avatar asked Mar 25 '19 10:03

Jad S


People also ask

How do you kill a running lambda function?

You cannot kill a running lambda function. Though there is another way by which you can set concurrency limit to 0. This will stop it from starting any more executions.

How do you stop a running Lambda that is stuck in a recursive loop?

How do you stop a running Lambda that is stuck in a recursive loop? Delete the function. Set the function concurrent execution limit to 0 while you update the code.

How do you stop lambda function execution in Python?

When you call exit() like that you are killing everything instead of returning from your function like the Lambda server expects. In other words, exit() is always going to result in that error message. You need to return from your function instead.


2 Answers

There's no way to kill a running lambda. However, you can set concurrency limit to 0 to stop it from starting any more executions

e.g.

$ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions 0 

https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html

like image 134
ubi Avatar answered Sep 21 '22 03:09

ubi


Following on from ubi's answer, you can also set the concurrency via the AWS console. Go to the Lambda you want to stop and click on the Throttle button:

enter image description here

You will get a modal explaining the concurrency will be set to 0 and no more Lambdas will run:

enter image description here

like image 43
Jeff S. Avatar answered Sep 21 '22 03:09

Jeff S.