Help, my Lambda won't stop 😱 ! How To Stop An AWS Lambda Execution.
Tags: devops, serverless, cloud, aws
Published: 2020-11-06 06:30:37

---
title: Help, my Lambda won't stop 😱 ! How To Stop An AWS Lambda Execution.
published: true
date: 06/11/2020
tags: devops, serverless, cloud, aws
canonical_url: https://www.thedevcoach.co.uk/can-you-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](https://i1.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/lambda.png?fit=300%2C197&ssl=1)

**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](https://i2.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/Screenshot-2020-10-23-at-06.25.58.png?resize=760%2C339&ssl=1)

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](https://docs.aws.amazon.com/cli/latest/reference/lambda/put-function-concurrency.html). Like so…

<script src="https://gist.github.com/loujaybee/c0d070fe0ca9446f7512fe700e815bfe.js"></script>

## Disable Integrations (e.g. Kinesis)

![](https://i1.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/kinesis-lambda.png?resize=760%2C439&ssl=1)

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](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-event-source-mapping.html) 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](https://docs.aws.amazon.com/streams/latest/dev/kinesis-extended-retention.html), 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](https://i2.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/Screenshot-2020-10-23-at-06.27.22.png?resize=760%2C308&ssl=1)

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](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-configuration.html) method in the AWS CLI.

## Remove IAM Permissions

![](https://i0.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/permissions-lambda.png?resize=760%2C354&ssl=1)

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](https://i2.wp.com/www.thedevcoach.co.uk/wp-content/uploads/2020/10/Screenshot-2020-10-23-at-06.30.37.png?resize=760%2C246&ssl=1)

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](https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-configuration.html) 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.](https://www.thedevcoach.co.uk/understand-aws-lambda-console/) or for more on Serverless: [Serverless: An Ultimate Guide](https://www.thedevcoach.co.uk/serverless-ultimate-guide/).

---

The post [Can You Stop An AWS Lambda Execution?](https://www.thedevcoach.co.uk/can-you-stop-an-aws-lambda-execution/) appeared first on [The Dev Coach](https://www.thedevcoach.co.uk).

If you’re interested in Cloud I write a monthly [newsletter for Cloud Software Engineers](https://newsletter.thedevcoach.co.uk). 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.