GithubHelp home page GithubHelp logo

r-jangir / aws-lambda_ec2-ami-backups Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rajeshkrish12/aws-lambda_ec2-ami-backups

0.0 0.0 0.0 6 KB

AWS lambda triggering AMI's of EC2 instances and notify through SNS mail, when the AMI creation is triggered.

License: MIT License

Python 100.00%

aws-lambda_ec2-ami-backups's Introduction

AWS-Lambda_EC2-AMI-backups

It is to take AMI's of EC2 aws instances through AWS lambda and notify through mail, when the ami creation is triggered. Backup deletion code will be updated soon

Setting Up IAM Permissions

First create an IAM policy called "lambda-ec2ami_policy" with the following policy document:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:*"
            ],
            "Resource": "arn:aws:logs:*:*:*"
        },
        {
            "Effect": "Allow",
            "Action": "ec2:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sns:Publish"
            ],
            "Resource": "*"
        }
    ]
}

Next create an IAM role also called "lambda-ec2ami_role" select "AWS Lambda" as the Role type, then attach the "lambda-ec2ami" policy created above.

Add the SNS Topics ARN you want publish as a Lambda environment variable "aws_sns_arn"

This is optional environment variable if you want publish any topic, so you might receive email notification once AMI backing up was executed.

Create the Lambda Functions

Create a functions in Lambda using the Python 2.7 runtime. I recommend just using the 128 MB memory setting, and adjust the timeout to 10 seconds (longer in a larger environment). Set the event source to be "CloudWatch Events - Schedule" and set the Schedule expression to be a cron expression of your liking i.e. "cron(0 6 * * ? *)" if you want the job to be kicked off at 06:00 UTC.

Tagging your EC2 instances to backup

You will need to tag your instances in order for them to be backed up, below are the tags that will be used by the Lambda function:

Tag Key Tag Value Notes
Backup Value Not Needed
Retention Number of Days to Retain Snapshot Default is 7 Days

More Info

[if you need more details on setting this up please mail me to [email protected]]

aws-lambda_ec2-ami-backups's People

Contributors

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