Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconaurora
file-type-iconlambda-cleanup-snapshots
file-type-iconlambda-copy-shared-snapshot
file-type-iconlambda-create-snapshot
file-type-iconcreate-rds-snapshot
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconlambda-share-snapshot
file-type-iconrds
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconmodules
file-type-iconaurora
file-type-iconlambda-cleanup-snapshots
file-type-iconlambda-copy-shared-snapshot
file-type-iconlambda-create-snapshot
file-type-iconcreate-rds-snapshot
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconlambda-share-snapshot
file-type-iconrds
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.adoc
Database backup

Database backup

Snapshot your RDS databases and copy the snapshots to other AWS accounts on a scheduled basis for disaster recovery.

Code Preview

Preview the Code

mobile file icon

core-concepts.md

down

Data backup core concepts

How does this differ from RDS automatic snapshots?

Note that RDS comes with nightly snapshots by default. The main reason to use this function is:

  1. You want to take snapshots of your database more often than once per night.
  2. You want to store all of your snapshots in a separate AWS account for security and redundancy purposes.

How do you backup your RDS snapshots to a separate AWS account?

One of the main use cases for this module is to be able to store your RDS snapshots in a completely separate AWS account. That reduces the chances that you, or perhaps an intruder who breaks into your AWS account, can accidentally or intentionally delete all your snapshots.

Let's say you have an RDS database in account A and you want to store snapshots in account B. To set that up, you need to do the following:

  1. Deploy this lambda function (lambda-create-snapshot) and the lambda-share-snapshot lambda function in account A. Configure this lambda function to trigger the lambda-share-snapshot function by setting the following variables:

    module "create_snapshot" {
      source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/data-storage/lambda-create-snapshot?ref=v1.0.8"
    
      # ... (other params ommitted) ...
    
      share_snapshot_with_another_account = true
      share_snapshot_lambda_arn = "(ARN of the lambda-share-snapshot function)"
      share_snapshot_with_account_id = "(The ID of account B)"
    }
    
  2. This will make the snapshots from account A visible in account B, but it won't actually copy them into the account. To copy them into account B, deploy the lambda-copy-shared-snapshot module in account B and configure it with the account ID of account A:

    module "copy_shared_snapshot" {
      source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/data-storage/lambda-copy-shared-snapshot?ref=v1.0.8"
    
      # ... (other params ommitted) ...
    
      rds_db_identifier = "(The identifier of the RDS DB in account A)"
      rds_db_account_id = "(The ID of account A)"
    }
    

Why use lambda functions?

The reason we use lambda functions for handling snapshots is:

  1. It's easy to use scheduled events and schedule expressions to run a lambda function on a periodic basis that is more reliable than just using cron.

  2. You can give your lambda function access to RDS via IAM roles instead of using API keys with an external app.

  3. The main use case for these lambda snapshot modules is to copy RDS snapshots to an external AWS account. That means you need to run code in multiple accounts. It's easier to deploy the necessary lambda functions in each account and give those functions access to RDS via IAM roles than it is to create a CI job that can securely access both accounts.

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 vars.tf.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?