How to Disable and Re-enable an AWS Lambda Function (Step-by-Step Guide)


Managing the availability of your AWS Lambda functions is essential for maintaining performance, cost control, and operational reliability. While AWS Lambda does not provide a built-in “disable” feature like EC2 or RDS, you can still prevent a function from being triggered and re-enable it later using smart configuration techniques.


 Step-by-Step: Disabling a Lambda Function

Since AWS Lambda doesn't have a direct "Disable" button, here are effective methods to prevent it from running:

1. Remove or Comment Out Event Source Mappings

For functions triggered by event sources like SQS, DynamoDB, or Kinesis:

  • Navigate to Lambda Console > Your Function > Configuration > Triggers.

  • Select the trigger and click “Remove”.

  • Alternatively, if using the AWS CLI:


aws lambda delete-event-source-mapping --uuid <UUID>


To find the UUID:


aws lambda list-event-source-mappings --function-name <function_name>


2. Disable Scheduled Triggers (Amazon EventBridge / CloudWatch)

For cron-based or rate-based triggers:

  • Go to the Amazon EventBridge Console.

  • Find the rule associated with the Lambda.

  • Choose “Disable”.

Via AWS CLI:


aws events disable-rule --name <rule_name>


3. Detach API Gateway or Other Integrations

If your Lambda is triggered via API Gateway, remove or turn off the integration:

  • Open the API Gateway Console.

  • Edit the method, remove the Lambda integration, or set the integration to a mock.


 Step-by-Step: Re-enabling a Lambda Function

To resume the function's behavior:

1. Recreate or Reattach Event Source Mapping

Using the AWS CLI:


aws lambda create-event-source-mapping \

  --function-name <function_name> \

  --event-source-arn <source_arn> \

  --starting-position LATEST


Or add the trigger back via the Lambda console under the Triggers section.

2. Enable Scheduled Triggers Again

Using AWS CLI:


aws events enable-rule --name <rule_name>


Or via the console:

  • Go to EventBridge > Rules.

  • Choose the rule and click “Enable”.

3. Re-integrate API Gateway or Other Services

Reconfigure the integration to point to your Lambda function again via:

  • API Gateway Console, or

  • Using AWS CLI with put-integration.


 Best Practices

  • Tag Lambda functions with "Status":"Disabled" when temporarily disabling them.

  • Use IAM condition keys if needed to restrict access programmatically.

  • Document the reason for disabling in CloudWatch Logs or tagging metadata.

Comments

Popular posts from this blog

Podcast - How to Obfuscate Code and Protect Your Intellectual Property (IP) Across PHP, JavaScript, Node.js, React, Java, .NET, Android, and iOS Apps

YouTube Channel

Follow us on X