My AWS Lambda functions for personal use.
-
EC2/autostop_ec2/autostop-ec2
- Autostop EC2 instances with specified tag
-
EC2/autostop_ec2/reset-autostop-ec2
- Reset Autostop tags of specific EC2 instances
-
EC2/backup_ec2/create-ec2-backups
- Create AMI and Snapshot(s) for EC2 instance
- Managed by role: Lambda-EC2-Snapper
-
EC2/backup_ec2/tag-ec2-backups
- Tag Snapshots of AMI of EC2 instance
- Managed by role: Lambda-EC2-Snapper
-
EC2/backup_ec2/delete-ec2-backups
- Delete expired backup (AMI and the corresponding Snapshots)
- Managed by role: Lambda-EC2-Snapper
These scripts are intended to be run as AWS Lambda jobs triggered by an AWS CloudWatch scheduled event. They can also be run from command line or from crontab.
Lambda is a code execution service offered by Amazon Web Services. When you configure a single Lambda behavior, it runs based on events you specify without needing a server of any kind.
-
Create an AWS IAM Role that allows the AWS Lambda service to call AWS services (e.g. Lambda-EC2-Snapper).
-
Create a new AWS Lambda function with the contents of create-ec2-backups.py. Configure the DEFAULTS as appropriate for your environment.
-
Add a new CloudWatch Schedule Trigger for the Lambda function at the interval you require.
-
Wait for CloudWatch to trigger the scheduled event or use the AWS Lambda "Test" button to run manually.
-
Set up AWS configure to store your Access Key ID and Secret Access Key in
~/.aws
. See "Configuring the AWS Command Line Interface" for more details. -
Change
profile_name
andDEFAULTS
in the main of the scripts -
Build
virtualenv env
. env/bin/activate (on linux; or env\Scripts\activate on Windows)
pip install -r requirements.txt