Skip to main content
Data Storage Modules 0.35.0Last updated in version 0.31.4

Delete Snapshots Lambda Module

View SourceRelease Notes

This 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

main.tf

# ------------------------------------------------------------------------------------------------------
# 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.35.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 = <number>

# The ARN of the RDS database
rds_db_arn = <string>

# The identifier of the RDS database
rds_db_identifier = <string>

# 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 = <bool>

# 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 = <string>

# ----------------------------------------------------------------------------------------------------
# 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 = ""

}


Reference

Required

max_snapshotsnumberrequired

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.

rds_db_arnstringrequired

The ARN of the RDS database

rds_db_identifierstringrequired

The 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_expressionstringrequired

An 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_allbooloptional

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.

false
create_resourcesbooloptional

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.

true
lambda_namespacestringoptional

Namespace 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.

null
schedule_namespacestringoptional

Namespace all Lambda scheduling resources created by this module with this name. If not specified, the default is lambda_namespace with '-scheduled' as a suffix.

null
snapshot_namespacestringoptional

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.

""