Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Automatic AWS Lambda EC2 Snapshots using Node or Phython

Notifications You must be signed in to change notification settings

OpenSaasAU/lambda-ec2-snapshots

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Setup Guide

  • Copy the code from either snapshots.js or snapshots.py into a new Lambda function
  • Use a similar IAM policy to allow access to EC2 tags, snapshots, etc. Replace ec2-snapshots with the name of your Lambda function
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "logs:CreateLogGroup",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:*:*:log-group:/aws/lambda/ec2-snapshots:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:CreateSnapshot",
                "ec2:DeleteSnapshot",
                "ec2:CreateTags",
                "ec2:ModifySnapshotAttribute",
                "ec2:ResetSnapshotAttribute",
                "ec2:Describe*"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
  • Set the Lambda's function Trigger to a "CloudWatch Events - Schedule". This can be set from within the Lambda function console under the "Triggers" tab
  • To manually set the region. Confgiure the input of the Lambda function, set to "Constant (JOSN text)" and enter the region in JSON format for example:
{ "region" : "us-east-1" }
  • You can then setup multiple Cloudwatch rules for different regions pointing to the same Lambda function.
  • Add the following tags to the EC2 instance(s) you want snapshots created
Tag Value Description
Backup tags the EC2's volume for a snapshot to be created
Retention int number of days to keep the snapshot (for example 7 would be keep the snapshot for 7 days)

About

Automatic AWS Lambda EC2 Snapshots using Node or Phython

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 51.5%
  • JavaScript 48.5%