https://medium.com/@gardarr/reducing-aws-ec2-operating-costs-using-a-lambda-scheduler-833d4f19857
Author: Gar Lee
Problem: EC2s are billed hourly and are often unused during off-hours. This creates an inflated operating cost and is usually overlooked.
Solution: Stand up AWS Lambda with Cloudwatch cron triggers to execute start/stop commands given an existing EC2 instance ID.
Performance:
Buildtime and runtime on Python 3.7
Deployed code bundle size is < 1kb
Highly reusable across all planes
ec2:StartInstances
ec2:StopInstances
$ touch env.list
$ cat env.list
> AWS_REGION=YOUR_REGION
AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY
sh docker-deploy.sh <lambda-assume-role-arn> <ec2-instance-id>
By default, the start time for EC2 is 8AM PDT and stop time is at 10PM PDT. Parameterization feature will be included soon!