Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

kyhau/aws-ec2-lambdas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS lambda functions for EC2

Python 2.7 | 3.6 Build Status

My AWS Lambda functions for personal use.

Scripts being run through Lambda

  1. EC2/autostop_ec2/autostop-ec2

    • Autostop EC2 instances with specified tag
  2. EC2/autostop_ec2/reset-autostop-ec2

    • Reset Autostop tags of specific EC2 instances
  3. EC2/backup_ec2/create-ec2-backups

    • Create AMI and Snapshot(s) for EC2 instance
    • Managed by role: Lambda-EC2-Snapper
  4. EC2/backup_ec2/tag-ec2-backups

    • Tag Snapshots of AMI of EC2 instance
    • Managed by role: Lambda-EC2-Snapper
  5. EC2/backup_ec2/delete-ec2-backups

    • Delete expired backup (AMI and the corresponding Snapshots)
    • Managed by role: Lambda-EC2-Snapper

How the scripts are used

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.

Run from AWS Lambda

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.

  1. Create an AWS IAM Role that allows the AWS Lambda service to call AWS services (e.g. Lambda-EC2-Snapper).

  2. Create a new AWS Lambda function with the contents of create-ec2-backups.py. Configure the DEFAULTS as appropriate for your environment.

  3. Add a new CloudWatch Schedule Trigger for the Lambda function at the interval you require.

  4. Wait for CloudWatch to trigger the scheduled event or use the AWS Lambda "Test" button to run manually.

Run from Command Line

  1. 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.

  2. Change profile_name and DEFAULTS in the main of the scripts

  3. Build

virtualenv env
. env/bin/activate    (on linux; or env\Scripts\activate on Windows)
pip install -r requirements.txt

About

My AWS Lambda functions for personal use.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages