Giter Site home page Giter Site logo

serverless-ec2-backup's Introduction

Overview

Detailed decription of the backup procedure is decribed here: https://e-pilot.atlassian.net/wiki/spaces/PLAY/pages/1775337487/AWS+-+Configure+Automated+backup+for+EC2

The repository contains the code for a serverless deployment of a lambda function. The lambda function is combination of the 2 functions deployed to automatically

  1. Create AMI backups for instances having a specific tag "BackUp".
  2. Cleanup AMI backups taken by Step 1 after certain configurable retention period ("RETENTION_DAYS" environment variable).
  • The tag name "BackUp" is case sensitive and should be used with the appropriate case. Example:- "BackUp"
  • Environment variable RETENTION_DAYS (in number of days) should be configured

Prerequisites

  • You need to add a tag to the desired EC2 instance to be backed-up. You can use the following command to add tags manually.

  • For one instance

aws ec2 create-tags --resources i-05xxxxxxxxb220fb --tags Key=BackUp,Value=""
  • For multiple Instances
aws ec2 create-tags --resources i-05xxxxxxxxb220fb i-123xxxxxxxxbcdef0 --tags Key=BackUp,Value=""
  • The tag name "BackUp" is case sensitive and should be used with the appropriate case. Example:- "BackUp"

Deploy lambda

The below steps provide details on deploying this lambda function manually for testing purposes. It uses aws cli for deployment.

Deploying the function

The function can be deployed using the serverless binary.

Serverless

Deploying the function

the lambda function will require a role which will have privileges to describe the EC2 instances and work with the AMI images.

Deploy command (staging example):

aws lambda create-function --function-name test-ec2-backup --runtime python3.7 \
--zip-file fileb://serverless-ec2-backup.zip --handler handler.handler \
--role arn:aws:iam::882235782134:role/temp-lambda-ami-backup \
--environment "Variables={RETENTION_DAYS=100}"

Update function code

aws lambda update-function-code --function-name test-ec2-backup  --zip-file fileb://serverless-ec2-backup.zip

Logging

  • To ship logs of this lambda function using the automatic log shipper lambda function, please execute the below command to create an event source mapping.
aws lambda create-event-source-mapping \
    --function-name my-function \
    --batch-size 5 \
    --event-source-arn arn:aws:logs:eu-central-1:<AWS_ACCOUNT>:log-group:/aws/lambda/ec2-backup

References

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.