24

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?

Jad S
  • 2,285
  • 4
  • 22
  • 47
  • 2
    Max run time for a Lambda = 15 minutes, so even if it's infinitely looping or hung, it only gets 15 minutes to make a mess of things. – fusion27 Nov 05 '20 at 22:19

4 Answers4

29

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

ubi
  • 3,523
  • 1
  • 29
  • 43
  • 1
    What's the default concurrency limit? (Edit, nvm found that it's [1000 by default](https://aws.amazon.com/about-aws/whats-new/2017/11/set-concurrency-limits-on-individual-aws-lambda-functions/)) – LaundroMat Sep 27 '20 at 18:53
  • 2
    While this answer is true and will work for future invocations of the function... To kill currently running Lambdas you should DELETE the function. This is the only way to kill CURRENTLY RUNNING Lambdas. If you are using Infra-as-code then recreating the Lambda later should not be an issue. – ElasticThoughts Jul 28 '21 at 17:59
9

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

Jeff S.
  • 933
  • 1
  • 11
  • 16
6

To stop my Lambda function which was in an infinite loop because I had an error in its iterative logic to ListObjects within an S3 bucket, I simply altered the IAM policy that gave the Lambda function access to the S3 bucket causing it to fail and thus breaking out of my infinite loop which is designed to return from the Lambda function upon encountering an error.

Neoheurist
  • 2,713
  • 3
  • 32
  • 50
1

We had a problem of a aws lambda function running continuously. Figured it only after a week, by the time it was a huge bill. Setting concurrency to zero stopped it temporarily, but it was back when the concurrency was set back to normal. But a simple trick saved us, we revoked the active sessions, which stopped all the function calls. (Configurations>Permissions>Execution role) It attaches an inline policy named AWSRevokeOlderSessions to the role. Remove this policy after the job is done. Be careful with this as it stops all active sessions of all users logged in. Do it only in no use time. Also, if you don't remove the revoke policy it creates problems in new sessions too, though it is mentioned otherwise.

S Jacob
  • 11
  • 1