How do automatic disable an AWS Lambda function without removing the function using AWS CDK — Infrastructure as Code

You probably know the problem and you are afraid of using the Lambda function if it's going crazy and can cost you a lot of money on nothing useful result.

This problem can be prevented by monitoring each Lambda function where you have the risk and pausing it if it hit your limit of runs over an amount of time.

What you will learn in this article will be how you can use CloudWatch Alarm combined with Metric data to trigger a Lambda function to disable a second Lambda to keep the damage very low if something is going crazy in your Lamda function.

Infrastructure stack for Lambda with SNS Topic and CloudWatch alarm

Our infrastructure will contain a Simple Notification Service (SNS Topic), Two Lambda functions, one test function, and the function to disable the test function, then there are attached is a CloudWatch Alarm there triggered based on the Lambda metric invocations data, in the end, we are adding our Lambda to Simple Notification Service (SNS Topic).

--

--

Paris Nakita Kejser
DevOps Engineer, Software Architect and Software Developering

DevOps Engineer, Software Architect, Software Developer, Data Scientist and identify me as a non-binary person.