Tag-Based Automation • API Trigger • DynamoDB Logging • CI/CD Deployment
This repository implements a production-ready EC2 auto-shutdown system designed to reduce AWS costs, enforce governance, and provide safe manual control mechanisms for operators.
The system evolved incrementally from a simple scheduled Lambda function into a fully automated CloudOps workflow with environment isolation, audit logging, and CI/CD-driven deployments. The architecture mirrors patterns used in real-world AWS production environments.
EC2 Instances
→ Amazon EventBridge (scheduled trigger)
→ AWS Lambda (shutdown logic)
→ Tag-based filtering and optional API override
→ Amazon DynamoDB (audit logging)
Optional deployment flow:
GitHub Actions → CI/CD → Environment-specific stacks (Beta / Production)
A Lambda function automatically stops EC2 instances on a defined schedule using Amazon EventBridge. This removes the need for manual intervention and helps eliminate unnecessary compute spend.
Shutdown behavior is controlled using EC2 instance tags. Only instances matching required tags are eligible for shutdown, preventing accidental disruption of protected or production workloads.
Example tags:
AutoShutdown = TrueEnvironment = Dev
This enables safe, fine-grained control across shared AWS accounts.
An HTTP endpoint is exposed through Amazon API Gateway, allowing operators to manually trigger shutdowns without accessing the AWS Console.
Example request:
GET /shutdown?key=Environment&value=DevThis is useful for incident response, testing, or ad-hoc cost control.
Separate pipelines and stacks are maintained for beta and production environments. This ensures:
Safe testing of changes
No impact to production resources
Predictable deployments
Environment isolation is enforced through CI/CD workflows and environment-specific configuration.
Every shutdown action is logged to DynamoDB with structured metadata, including:
EC2 instance ID
Matched tags
Trigger source (scheduled or API)
Timestamp
This provides full traceability for operational actions and supports auditing, troubleshooting, and compliance requirements.
GitHub Actions is used to automate deployments:
Package and zip Lambda code
Upload artifacts to Amazon S3
Deploy CloudFormation stacks
Promote changes from beta to production
This makes the deployment process repeatable, version-controlled, and environment-aware.
AWS Lambda
Amazon EC2
Amazon EventBridge
Amazon API Gateway
Amazon DynamoDB
Amazon S3
AWS IAM
GitHub Actions
Reduce AWS spend by stopping idle EC2 instances
Enforce tag-based infrastructure policies
Enable safe manual shutdowns for DevOps teams
Maintain audit trails for compliance and governance