There are a few reasons why you may want to stop a Lambda. Either the Lambda is buggy or performing incorrectly, your Lambda is reading an event source like kinesis and you need to pause it, or your Lambda is being constantly retried.
Can you stop an AWS Lambda Function? There is no way to stop a currently executing AWS Lambda function. But you can stop future invocations by setting concurrency to zero or disabling integrations.
So, there’s a few different aspects to the topic of stopping a Lambda. Let me take you through some different options for stopping your AWS Lambda function so that you can decide which one makes most sense for your situation.
Set Concurrency To Zero
One of the main ways you can stop your Lambda is to set the concurrency limit to zero. Note, setting concurrency to zero will not stop any currently processing lambda functions, but it will prevent any new lambda functions from starting.
You can set your lambda concurrency to zero from the lambda console interface by clicking the throttle button on the lambda function page. Or you can set the concurrency property via the CLI. Like so…
Disable Integrations (e.g. Kinesis)
Another option you have for stopping your Lamba execution is to disable your integrations. If you’re using something like Kinesis, for instance, by disabling your integration you will prevent Kinesis from triggering future invocations.
You can “disable” a kinesis integration within AWS Lambda by clicking on your integration and pressing “disable”. Note: disabling the integration with Kinesis will not drop messages from your kinesis stream until they reach your kinesis retention period, which defaults to 24 hours.
You can use the same disabling method for different integrations, but dependent on the integration you will want to check whether messages will be dropped, or whether you can resume again reading the events in the future.
Set A Lower Timeout
One reason that you might be searching how to stop your Lambda is because it’s running longer than you expected. The lifetime of a Lambda function can be up to 15 minutes, but depending on your implementation, this might not be desired.
The timeout setting sets the amount of time the lambda function will run before being completely stopped by AWS, regardless of the functions outcome. Ideally you’ll set your timeout just above your expected execution time so if your function over-runs then it is stopped immediately.
You can set the timeout property in the basic settings of your Lambda, or via the update-function-configuration method in the AWS CLI.
Remove IAM Permissions
Another option for stopping your Lambda function is to remove any relevant execution permissions. Before any resource can trigger your Lambda function your Lambda must have an associated permission on its IAM role.
If you want to stop future invocations a simple way to do this is by removing the related permission from the IAM role associated with your Lambda. You can find a link to the IAM role in the permissions tab of the Lambda.
The final solution to help stop your lambda function is to ensure you have the correct retry attempts setup for your scenario. By default AWS Lambda will retry asynchronous events several times.
It might be that these retried invocations are the invocations that you want to cancel, in which case you’ll want to set your retry attempts to zero.
You can find your retry settings in the “asynchronous invocation” section of the AWS Lambda console, or you can update the property using the AWS CLI update-function-configuration command.
Stop That Lambda
Hopefully this run through of options for stopping an AWS Lambda function helped to point you in the right direction.
To quickly recap what we covered: running Lambda functions cannot be stopped, but you can disable integrations such as kinesis or if needed, cut the invocations off by setting concurrency to zero or removing IAM permissions.
For a full run through of the different settings for AWS Lambda, be sure to check out the article: Master the AWS Lambda Console: A Comprehensive Walkthrough. or for more on Serverless: Serverless: An Ultimate Guide.
- Open Up The Cloud Newsletter #30 (January Recap 2022) - March 1, 2022
- Open Up The Cloud Newsletter #29 (November Recap 2021) - January 20, 2022
- Open Up The Cloud Newsletter #28 (October Recap 2021) - January 17, 2022