Scripts for starting and stopping AWS EC2 instances. You can place these scripts in your cron and manage instance usage during weekends for example.
- Make scripts executables
chmod +x ec2_start_instances.yml
chmod +x ec2_stop_instances.yml
virtualenv pyenv
pip install -r requirements.txt
- Rename and complete variable scripts
mv vars/aws_config-sample.yml vars/aws_config.yml
mv vars/ec2_instances-sample.yml vars/ec2_instances.yml
- ec2_instances.yml
- AWS region:
region: eu-west-1
- Instance IDs to control:
instance_ids:
- i-XXXXXX
- i-XXXXXX
- Project name for control over
vars/ec2_instances<project>.yml
project: '_myProject'
- Start instances
./ec2_start_instances.yml
# or
./ec2_start_instances.yml -e project=<project>
- Stop instances
./ec2_stop_instances.yml
# or
./ec2_stop_instances.yml -e project=<project>
Edit /etc/crontab
and place the following lines for auto stop-start on the weekends. With vars/ec2_instances_myProject.yml
:
0 1 15 ? * FRI * ./ec2_stop_instances.yml -e project=_myProject
0 1 9 ? * MON * ./ec2_start_instances.yml -e project=_myProject
- Carles San Agustin - carlessanagustin.com
- MIT License