Delete Snapshots Lambda Module
View SourceRelease NotesThis module creates an AWS Lambda function that runs periodically and deletes old snapshots of an Amazon Relational Database (RDS) database. The module allows you to specify the maximum number of snapshots you want to keep and any time that number of snapshots is exceeded, it will delete the oldest snapshots.
Note that to use this module, you must have access to the Gruntwork Continuous Delivery Infrastructure Package (terraform-aws-ci). If you need access, email support@gruntwork.io.
How do you configure this module?
This module allows you to configure a number of parameters, such as which database to backup, how often to run the backups, what account to share the backups with, and more. For a list of all available variables and their descriptions, see variables.tf.
Sample Usage
- Terraform
- Terragrunt
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S LAMBDA-CLEANUP-SNAPSHOTS MODULE
# ------------------------------------------------------------------------------------------------------
module "lambda_cleanup_snapshots" {
source = "git::git@github.com:gruntwork-io/terraform-aws-data-storage.git//modules/lambda-cleanup-snapshots?ref=v0.26.0"
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# The maximum number of snapshots to keep around of the given DB. Once this number
# is exceeded, this lambda function will delete the oldest snapshots.
max_snapshots = <INPUT REQUIRED>
# The ARN of the RDS database
rds_db_arn = <INPUT REQUIRED>
# The identifier of the RDS database
rds_db_identifier = <INPUT REQUIRED>
# If set to true, this RDS database is an Amazon Aurora cluster. If set to false,
# it's running some other database, such as MySQL, Postgres, Oracle, etc.
rds_db_is_aurora_cluster = <INPUT REQUIRED>
# An expression that defines how often to run the lambda function to clean up
# snapshots. For example, cron(0 20 * * ? *) or rate(5 minutes).
schedule_expression = <INPUT REQUIRED>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# If set to true, you will be able to set max_snasphots to zero, and the cleanup
# lambda job will be allowed to delete ALL snapshots. In production usage, you
# will NEVER want to set this to true.
allow_delete_all = false
# Set to false to have this module skip creating resources. This weird parameter
# exists solely because Terraform does not support conditional modules. Therefore,
# this is a hack to allow you to conditionally decide if this module should create
# anything or not.
create_resources = true
# Namespace all Lambda resources created by this module with this name. If not
# specified, the default is var.rds_db_identifier with '-delete-snapshots' as a
# suffix.
lambda_namespace = null
# Namespace all Lambda scheduling resources created by this module with this name.
# If not specified, the default is var.lambda_namespace with '-scheduled' as a
# suffix.
schedule_namespace = null
# Namespace of snapshots that will be cleaned up by this module. If specified then
# it will match snapshots with this value as a hyphenated suffix. If this value is
# empty then all manual snapshots will be evaluated for cleanup.
snapshot_namespace = ""
}
# Coming soon!
Reference
- Inputs
- Outputs
Required
max_snapshotsnumberThe maximum number of snapshots to keep around of the given DB. Once this number is exceeded, this lambda function will delete the oldest snapshots.
rds_db_arnstringThe ARN of the RDS database
rds_db_identifierstringThe identifier of the RDS database
If set to true, this RDS database is an Amazon Aurora cluster. If set to false, it's running some other database, such as MySQL, Postgres, Oracle, etc.
schedule_expressionstringAn expression that defines how often to run the lambda function to clean up snapshots. For example, cron(0 20 * ? ) or rate(5 minutes).
Optional
allow_delete_allboolIf set to true, you will be able to set max_snasphots to zero, and the cleanup lambda job will be allowed to delete ALL snapshots. In production usage, you will NEVER want to set this to true.
falsecreate_resourcesboolSet to false to have this module skip creating resources. This weird parameter exists solely because Terraform does not support conditional modules. Therefore, this is a hack to allow you to conditionally decide if this module should create anything or not.
truelambda_namespacestringNamespace all Lambda resources created by this module with this name. If not specified, the default is rds_db_identifier with '-delete-snapshots' as a suffix.
nullschedule_namespacestringNamespace all Lambda scheduling resources created by this module with this name. If not specified, the default is lambda_namespace with '-scheduled' as a suffix.
nullsnapshot_namespacestringNamespace of snapshots that will be cleaned up by this module. If specified then it will match snapshots with this value as a hyphenated suffix. If this value is empty then all manual snapshots will be evaluated for cleanup.
""