Redis Copy Snapshot Module
This module copies an existing Redis snapshot to an external s3 bucket. You can find more information from Exporting a backup page.
When do I use this
Exporting a backup can be helpful if you need to launch a cluster in another AWS Region. You can export your data in one AWS Region, copy the .rdb file to the new AWS Region, and then use that .rdb file to seed the new cluster instead of waiting for the new cluster to populate through use. For information about seeding a new cluster, see Seeding a new cluster with an externally created backup. Another reason you might want to export your cluster's data is to use the .rdb file for offline processing.
How it Works
It deploys a lambda function that uses boto3::elasticache::copy_snapshot
to export the Redis snapshot to a S3 bucket.
Refer to [copy_snapshot documentation for more
information: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticache/client/copy_snapshot.html
How to Create a Snapshot
You can manually create a backup following the instruction: Making manual backups.
Permission Required
The caller of the module needs to have the appropriate permission on the s3 bucket and the elastic cache cluster. The detailed permission requirement is explained in detail here: Exporting a backup page. You can also refer to redis_copy_snapshot module as an example.
Encryption Limitation
It seems like you can only export the snapshot encrypted with default AWS managed KMS key (aws/elasticache
). If you
try to export a snapshot encrypted with CMK (Customer Managed Key), you will get an error like this:
Error exporting snapshot: An error occurred (InvalidParameterCombination) when calling the CopySnapshot operation: AWS Key Management Service Customer Managed CMK cannot be used for encrypting exported snapshots in S3. Please encrypt the exported snapshot file in S3 if necessary.
Sample Usage
- Terraform
- Terragrunt
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S REDIS_COPY_SNAPSHOT MODULE
# ------------------------------------------------------------------------------------------------------
module "redis_copy_snapshot" {
source = "git::git@github.com:gruntwork-io/terraform-aws-cache.git//modules/redis_copy_snapshot?ref=v0.23.0"
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# The ARN of an existing snapshot from which to make a copy.
source_snapshot_arn = <string>
# The name of an existing snapshot from which to make a copy.
source_snapshot_name = <string>
# The ARN of the s3 bucket to export the snapshot to.
target_s3_bucket_arn = <string>
# The name of the s3 bucket to export the snapshot to.
target_s3_bucket_name = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# A name for the exported snapshot copy. ElastiCache does not permit
# overwriting a snapshot, therefore this name must be unique within its
# context - ElastiCache or an Amazon S3 bucket if exporting. Defaults to the
# same name as the `source_snapshot_name`.
target_snapshot_name = null
}
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S REDIS_COPY_SNAPSHOT MODULE
# ------------------------------------------------------------------------------------------------------
terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-cache.git//modules/redis_copy_snapshot?ref=v0.23.0"
}
inputs = {
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# The ARN of an existing snapshot from which to make a copy.
source_snapshot_arn = <string>
# The name of an existing snapshot from which to make a copy.
source_snapshot_name = <string>
# The ARN of the s3 bucket to export the snapshot to.
target_s3_bucket_arn = <string>
# The name of the s3 bucket to export the snapshot to.
target_s3_bucket_name = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# A name for the exported snapshot copy. ElastiCache does not permit
# overwriting a snapshot, therefore this name must be unique within its
# context - ElastiCache or an Amazon S3 bucket if exporting. Defaults to the
# same name as the `source_snapshot_name`.
target_snapshot_name = null
}
Reference
- Inputs
- Outputs
Required
source_snapshot_arn
stringThe ARN of an existing snapshot from which to make a copy.
source_snapshot_name
stringThe name of an existing snapshot from which to make a copy.
target_s3_bucket_arn
stringThe ARN of the s3 bucket to export the snapshot to.
target_s3_bucket_name
stringThe name of the s3 bucket to export the snapshot to.
Optional
target_snapshot_name
stringA name for the exported snapshot copy. ElastiCache does not permit overwriting a snapshot, therefore this name must be unique within its context - ElastiCache or an Amazon S3 bucket if exporting. Defaults to the same name as the source_snapshot_name
.
null