This project provides a sample implementation of a Lambda function which when invoked will create a new RDS database manual snapshot, as well as delete any old manual snapshots. The rules and snapshot ages for creation and deletion is configurable and specified through Lambda Environment Variables. Using an EventBridge rule, the Lambda function is invoked automatically based on a schedule expression (similar to cron). All infrastructure setup in this project is handled using Terraform configuration scripts.
TBD
Follow these steps to get up and running with a fully working environment:
Before you can start working with Terraform code provided here, you must have a few software tools installed on your local workstation or build server. These are:
You will also need an AWS account (signup here for a free tier account if you don't already have one).
Open a Terminal, and run the following command from a directory where you want to download the Github repo code:
git clone git@github.com:asksac/ManageRdsSnapshots.git
ℹ️ There are several ways of cloning a Github.com repo. For more details, refer to this page
The Terraform module in this project defines several input variables that must be set
based on your environment before you can apply the Terraform configuration. You may
set input values using a module configuration block from your own Terraform project.
Or, you may run this project as a root module directly, and set input values in
a file named terraform.tfvars in the project's root directory. An example
terraform.tfvars might look like this:
aws_profile = "default"
aws_region = "us-east-1"
app_name = "ManageRdsSnapshots"
app_shortcode = "MRS"
aws_env = "dev"
lambda_name = "ManageRdsSnapshots"
db_instance_id = "ora-rds01"
snapshot_max_age_in_days = 30
min_days_since_last_snapshot = 2
schedule_expression = "cron(0 8 * * ? *)"
For your testing, make sure to change above values based on your environment setup.
These input values affect the operation of deployed Lambda function:
db_instance_id(required) - specify RDS database instance id whose snapshot to managesnapshot_max_age_in_days(defaults to 0) - snapshots that are older than specified value in days will be deletedsnapshot_max_age_in_months(defaults to 0) - an alternate way to set maximum snapshot age in months (if bothsnapshot_max_age_in_daysandsnapshot_max_age_in_monthsare specified thensnapshot_max_age_in_daystakes precedence)min_days_since_last_snapshot(defaults to 0) - lambda will maintain a gap of specified days since last manual snapshot (if 0, new snapshot will be created every run)schedule_expression- sets a cron expression to invoke lambda automatically on schedule
You're now ready for installation, which is to deploy the Terraform configuration. Run the following commands in a Terminal from the project root directory:
terraform init
terraform applySecond command above will first run plan phase of Terraform, and output a list of
resources that Terraform will create. After verifying, enter yes to proceed with resource
creation. This step may take a few minutes to complete.
- MIT license
- Copyright 2021 © Sachin Hamirwasia