Skip to main content

Module: ec2-ami-backup

This repo contains a terraform module that creates two lambda functions that will create AMI automatically at regular intervals. It is based on the code at https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups/ and https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups-2/.

Usage

Include this repository as a module in your existing terraform code:

module "lambda_ami_backup" {
source = "git::https://github.com/cloudposse/terraform-aws-ec2-ami-backup.git?ref=tags/0.3.2"

name = "${var.name}"
stage = "${var.stage}"
namespace = "${var.namespace}"
region = "${var.region}"
ami_owner = "${var.ami_owner}"
instance_id = "${var.instance_id}"
retention_days = "14"
}

Examples

Example on excluding some of attached EBS volumes:

module "lambda_ami_backup" {
source = "git::https://github.com/cloudposse/terraform-aws-ec2-ami-backup.git?ref=tags/0.3.2"

name = "${var.name}"
stage = "${var.stage}"
namespace = "${var.namespace}"
region = "${var.region}"
ami_owner = "${var.ami_owner}"
instance_id = "${var.instance_id}"
retention_days = "14"

block_device_mappings = [
{ "DeviceName" = "/dev/xvdf", "NoDevice" = "" },
{ "DeviceName" = "/dev/xvdg", "NoDevice" = "" },
]
}