Python scripts using AWS boto3 to automatically stop EC2 instances on a schedule, deployed as AWS Lambda functions with CloudWatch cron triggers.
Automates EC2 instance shutdown to reduce AWS costs by stopping instances when they are not needed (e.g. outside business hours). Configured with a cron job in AWS Console (CloudWatch Events / EventBridge).
| Tool | Purpose |
|---|---|
| Python | Core language |
| AWS boto3 | AWS SDK — interact with EC2 |
| AWS Lambda | Serverless function runtime |
| AWS CloudWatch Events | Cron-based scheduling trigger |
| AWS EC2 | Compute instances being managed |
- Using
boto3.client("ec2")to programmatically stop instances - Filtering instances by tag or instance ID
- Lambda handler pattern:
def lambda_handler(event, context) - Scheduling via CloudWatch Events cron expression (e.g.
cron(0 18 * * ? *)= 6pm daily)
| File | Description |
|---|---|
aws scripts.py |
Lambda function to stop EC2 instances |
README.md |
Documentation |
- Zip
aws scripts.pyand upload to AWS Lambda - Set the handler to
aws scripts.lambda_handler - Attach IAM role with
ec2:StopInstancespermission - Add a CloudWatch Events trigger with your desired cron schedule
- Cloud automation with Python and AWS SDK (boto3)
- Serverless architecture with AWS Lambda
- Cost optimisation through scheduled instance management
- Infrastructure scripting applicable to DataOps and CloudOps workflows
Part of a broader data engineering portfolio — view more