How to Disable and Re-enable an AWS Lambda Function

AWS Lambda functions are a critical part of many serverless architectures, but there might be situations where you need to temporarily…

How to Disable and Re-enable an AWS Lambda Function
Photo by Mehmet Ali Peker on Unsplash

AWS Lambda functions are a critical part of many serverless architectures, but there might be situations where you need to temporarily disable or re-enable a function. This article will guide you through both the command-line (CLI) and graphical user interface (GUI) methods to manage your Lambda functions effectively.

Method 1: Using the AWS CLI

The AWS Command Line Interface (CLI) provides a straightforward way to disable and re-enable Lambda functions by adjusting their concurrency settings.

Prerequisites

Ensure you have:

  • Installed and configured the AWS CLI.
  • Appropriate IAM permissions to manage Lambda functions.

Disable a Lambda Function

To disable a function, you set its reserved concurrency to 0. This prevents it from being invoked

aws lambda put-function-concurrency --function-name <function-name> --reserved-concurrent-executions 0

Replace <function-name> with the name of your Lambda function.

Re-enable a Lambda Function

Re-enabling the function involves either removing the reserved concurrency limit or setting it to a positive value.

Option 1: Remove the Concurrency Limit

aws lambda delete-function-concurrency --function-name <function-name>

Option 2: Set a Positive Concurrency Limit

aws lambda put-function-concurrency --function-name <function-name> --reserved-concurrent-executions <limit>

Replace <limit> with the desired number of concurrent executions.

Verify the Changes

You can confirm the current concurrency settings with this command:

aws lambda get-function-concurrency --function-name <function-name>

Method 2: Using the AWS Management Console (GUI)

The AWS Management Console provides an easy-to-use graphical interface to manage Lambda functions.

Disable a Lambda Function

  1. Log in to the AWS Management Console and navigate to the Lambda service.
  2. Locate and click on the function you want to disable from the list.
  3. In the function details page:
  • Go to the Configuration tab.
  • Scroll down to Concurrency and click Edit.
  • Set the Reserved concurrency to 0.
  • Click Save to apply the changes.

The function is now effectively disabled and will not process any requests.

Re-enable a Lambda Function

  1. Navigate to the same Lambda function in the Lambda service.
  2. Under the Configuration tab, locate Concurrency and click Edit.
  3. Either:
  • Remove the concurrency limit by unchecking the “Reserve concurrency” option.
  • Set a positive number in the “Reserved concurrency” field.

Click Save to re-enable the function.

Choosing the Right Method

  • AWS CLI: Ideal for automation, scripting, or when managing multiple functions.
  • AWS Management Console: Best for one-off adjustments or if you prefer a visual interface.

Both methods are straightforward and achieve the same goal of controlling the availability of your AWS Lambda functions. Choose the one that suits your workflow!