DEV Community

Lou (🚀 Open Up The Cloud ☁️)
Lou (🚀 Open Up The Cloud ☁️)

Posted on • Originally published at thedevcoach.co.uk on

Help, my Lambda won't stop 😱 ! How To Stop An AWS Lambda Execution.

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.

Lambda Logo

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

Throttle Lambda Function

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

Set Timeout Lambda

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.

Remove Retries

Retry Attempts

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.


The post Can You Stop An AWS Lambda Execution? appeared first on The Dev Coach.

If you’re interested in Cloud I write a monthly newsletter for Cloud Software Engineers. I spend the month digging around the internet for the best cloud engineering content and provide a monthly summary. I read every article I share, and I focus on fundamentals as much as possible.

Top comments (0)