Skip to content

Automatically backup EC2 to AMI by AWS lambda.

Notifications You must be signed in to change notification settings

amazing14/lambda_ami_backup

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Daily EC2 AMI Backup by lambda

This project using Terraform to help you deploy a AWS Lambda function with IAM Role and Cloudwatch Event.

simple darchitecture

If your EC2 has a tag key Backup and value ec2_ami_automation, then it'll be backup AMI by lambda.

EC2 Tag Example example

Prerequisites

  • terraform installed (version >= 0.12.1)
  • python3 (version >= 3.7) (if you want to test on your local)

Deployment guide

# Archive your python code.
$ ./build.sh


$ cd terraform/lambda_ami_backup

$ terraform init
$ terraform plan
$ terraform apply 

Configuration

If you want to customize, see terraform/lambda_ami_backup/variables.tf file.

variable "ec2_tag_key_env_var" {
  description = "The EC2's tag key that lambda looking up."
  default     = "Backup"
}

variable "ec2_tag_value_env_var" {
  description = "The EC2's tag value that lambda looking up."
  default     = "ec2_ami_automation"
}

variable "schedule_exp_ami_create" {
  description = "The cloudwatch event schedule expression to trigger ami create lambda function at 6PM daily"
  default     = "cron(0 18 * * ? *)"
}
variable "schedule_exp_ami_delete" {
  description = "The cloudwatch event schedule expression to trigger ami delete lambda function at 7PM daily"
  default     = "cron(0 19 * * ? *)"
}

variable "max_images" {
  description = "The maximun count of backup images"
  default     = 5
}

variable "aws_region" {
  description = "AWS region to deploy the ec2 AMI automation stack"
  default     = "us-east-1"
}

cron details: https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html

corn schedule generator: http://www.cronmaker.com/

About

Automatically backup EC2 to AMI by AWS lambda.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 54.9%
  • HCL 43.3%
  • Shell 1.8%