Skip to content

Instantly share code, notes, and snippets.

@gangassault343
gangassault343 / gist:1d46b314cb23ac3c7c84f0723ec36422
Last active September 22, 2025 14:52
python 3.9 code to automatically launch a new EC2 instance when any EC2 instance is terminated, you can use AWS Lambda with EventBridge (CloudWatch Events)
📦 What You’ll Need:
🔁 Architecture Overview
Component Role
EventBridge Rule -> Triggers on EC2 terminated event
Lambda Function -> Launches a replacement EC2 instance with same configuration
IAM Role -> for Lambda Allows reading EC2 instance info + launching new instance
🧠 EventBridge Rule Pattern (to use in AWS Console or IaC)
{
"source": ["aws.ec2"],