AWS Backup – Automating application database and storage backups, using AWS CDK

AWS Backup – Automating application database and storage backups, using AWS CDK - AWS CDK

AWS Backup is a managed service by AWS, that helps application developers leverage the AWS Cloud to automate the boring job of running regular backup tasks for their persistent data, monitoring existing backups, and cleanup older copies of backups as they are no longer needed.

Like other “horizontal” services like IAM and CloudWatch, AWS Backup integrates pretty well with a variety of other AWS services, out of the box. Such services include (as of writing):

  • EC2 instances and their images and volumes
  • AWS EBS volumes
  • S3 buckets
  • RDS database (including Aurora)
  • DynamoDB tables
  • Neptune databases
  • DocumentDB databases
  • EFS file systems
  • AWS FSx file systems
  • AWS Storage Gateway volumes
  • VMware workloads

With the help of Infrastructure as Code in general, and AWS CDK specifically – one can easily configure AWS Backup for the whole infrastructure of an application and never have to think about backups stuff that stores data persistently anymore (like databases).

Here’s an example of a trivia CDK app that is composed of multiple CloudFormation stacks that potentially might themselves include many many DynamoDB tables, S3 buckets, EFS volumes, etc (basically any of the resources described in the list above).

const app = new cdk.App();
const stackA = new StackA(app, 'StackA', {env});
const stackB = new StackB(app, 'StackB', {env});
const stackC = new StackC(app, 'StackC', {env});

The way to easily plug AWS Backup in the setup above is to first create a dedicated CloudFormation stack for the Backup Plan itself (Backup Plans are a concept within the AWS Backup service).

const stackForBackups = new Stack(app, 'Backups', {env});
// Daily, weekly and monthly with 5 year retention
const plan = backup.BackupPlan.dailyWeeklyMonthly5YearRetention(stackForBackups, 'Plan');

Then you can use the addSelection()method of the BackupPlan construct to easily add one or more supported resources that will be automatically backed up by AWS Backup (including whole CDK Stacks or a whole CDK app, like the example below).

plan.addSelection('backup-cdk-app', {
// or backup individual stacks and their supported resources
plan.addSelection('backup-cdk-app', {
resources:[stackA, stackB, stackC],

This has been a quick introduction to AWS Backups and the Backup Plans and how they are used in the AWS CDK context. Hope you found it useful.

Looking forward to your feedback in the comments below.

Need help? Get in touch