Code Monkey home page Code Monkey logo

ec2-backup's Introduction

ec2-backup

This Lambda function performs snapshot backups of EC2 instances (inherantly to S3) with custom retention schemes based on tags defined against those instances and sends email notifications through SES with a daily status report.

Installation

IAM Policy Document

The Lambda function requires the following permissions:

  • ec2:DescribeInstances
  • ec2:DescribeVolumes
  • ec2:CreateSnapshot
  • ec2:DeleteSnapshot
  • ec2:DescribeSnapshots
  • ec2:CreateTags
  • ses:SendEmail
  • ses:SendRawEmail

These can be defined in IAM with the following policy document.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:*"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": "ec2:Describe*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:CreateSnapshot",
                "ec2:DeleteSnapshot",
                "ec2:CreateTags",
                "ec2:ModifySnapshotAttribute",
                "ec2:ResetSnapshotAttribute"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "ses:SendEmail",
                "ses:SendRawEmail"
            ],
            "Resource": "*"
        }
    ]
}

Configuration

At the top of the script, a there are a number of configuration directives:

  • regions (default: [region where Lambda function is running]) - list of regions to snapshot
  • retention_days (default: 2) - integer number of days to keep snapshots. This is overridden by specifying a 'ec2_backup_count' tag on the VM with an integer of the number of backups to retain.
  • email_to - Specify an email address to send the logs to
  • email_from - Specify an email address to send the emails from.

SES Verified Senders

The Lambda function sends emails to notify administrators that the backup has taken place. This requires some initial setup:

  1. Go to Services -> SES
  2. Click on Email Addresses.
  3. Click "Verify new email address".
  4. Enter an email address to verify as a sender - e.g. [email protected]

An email will be sent to that email address - follow the directions to complete the verification. Also note that if the SES for your AWS account is in sandbox mode, you will also have to verify the recipient email adddress.

Scheduling

To schedule the backup, perform the following when installing the Lambda script:

  1. Click on the Triggers tab.
  2. Click "Add Trigger".
  3. Add a new trigger source and search for "CloudWatch Events - Schedule". Specify the schedule expression in CRON format e.g. cron(0 3 * * ? *) - 3am UTC. Please note that times are in UTC.

Configuring EC2 Instances for Backup

Each instance you wish to backup requires the following two tags:

  • ec2_backup_enabled: Must be set to true to enable backups to be taken.
  • ec2_backup_count: Specifies the number of daily backups to retain.

ec2-backup's People

Contributors

jonathanthorpe avatar xinsnake avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.