Skip to content

Repository files navigation

EBS Backup Script for Lambda

This lambda function should be called by a CloudWatch event once a day. It iterates over all instances in the configured regions and creates a snapshot of every EBS volume of instances carrying the configured backup tag (the tag value is irrelevant and can be empty). Every snapshot is tagged with a DeleteOn date; snapshots whose DeleteOn date matches today are deleted.

Most of the code is taken from: https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups/

Installation

  • Create a Lambda function (with the latest Python runtime) and give it proper permissions (see next section)
  • Configure the function via the environment variables described below
  • Add a CloudWatch/EventBridge rule that triggers the function once a day

Configuration

The function is configured through environment variables:

VariableDefaultDescription
EC2_INSTANCE_TAGBackupInstances carrying this tag key are backed up
RETENTION_DAYS10Number of days a snapshot is kept before it is deleted
REGIONSeu-central-1Comma separated list of regions to process (e.g. eu-central-1,eu-west-1)

IAM

The Lambda function needs the following permissions to work:

  • ec2:DescribeInstances and ec2:DescribeSnapshots
  • ec2:CreateSnapshot and ec2:CreateTags
  • ec2:DeleteSnapshot

About

Small lambda function to create snapshots of EBS volumes

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages