This repository creates the automation necessary to export Amazon RDS snapshots to S3 for a specific database whenever a snapshot is created, whether created by an automated snapshot, manual, or by AWS Backup service.
-
Install the Amazon Cloud Development Kit (CDK).
-
Clone this repository and
cdinto it. -
Modify the arguments to the
RdsSnapshotExportPipelineStackconstructor in$/bin/cdk.tsaccording to your environment.dbName: This RDS database must already exist.rdsEvents: This should be indicate the RDS event ID and corresponsing snapshot type, where:rdsEventIdshould be:RdsEventId.DB_AUTOMATED_AURORA_SNAPSHOT_CREATEDfor Amazon Aurora databasesRdsEventId.DB_AUTOMATED_SNAPSHOT_CREATEDfor RDS automated snapshotsRdsEventId.DB_MANUAL_SNAPSHOT_CREATEDfor AWS Backup service or otherwise.RdsEventId.DB_BACKUP_SNAPSHOT_FINISHED_COPYfor AWS Backup service snapshots, created shortly after a prior snapshot has been taken.
rdsSnapshotTypeshould be:RdsSnapshotType.DB_AUTOMATED_SNAPSHOTfor Automated snapshots orRdsSnapshotType.DB_BACKUP_SNAPSHOTfor Backup service snapshots orRdsSnapshotType.DB_MANUAL_SNAPSHOTfor manual snapshots.
s3BucketName: An S3 bucket with the provided name will be created automatically for you.
For example, the following configuration will automatically export all snapshots and snapshot-copies, created by both the Automated service and by AWS Backup of an existing RDS database named
my-rds-db, to a new S3 bucket namedmy-rds-db-snapshots-export:dbName: 'my-rds-db', rdsEvents: [ { rdsEventId: RdsEventId.DB_AUTOMATED_SNAPSHOT_CREATED, rdsSnapshotType: RdsSnapshotType.DB_AUTOMATED_SNAPSHOT }, { rdsEventId: RdsEventId.DB_MANUAL_SNAPSHOT_CREATED, rdsSnapshotType: RdsSnapshotType.DB_BACKUP_SNAPSHOT }, { rdsEventId: RdsEventId.DB_BACKUP_SNAPSHOT_FINISHED_COPY, rdsSnapshotType: RdsSnapshotType.DB_BACKUP_SNAPSHOT } ], s3BucketName: 'my-rds-db-snapshots-export' -
Execute the following:
npm installnpm run cdk bootstrapnpm run cdk deploy
-
Open up your
<dbName>-rds-snapshot-exporterfunction in the AWS Lambda console and configure a test event using the contents of $/event.json OR $/event.aurora.json as a template, depending on whether or not you're using Amazon Aurora.- NOTE: The example content is a subset of an SNS event notification containing the minimum valid event data necessary to successfully trigger the Lambda function's execution. You should modify the
<SNAPSHOT_NAME>value within theMessagekey to match an existing RDS snapshot (e.g.rds:<dbName>-YYYY-MM-DD-hh-mm). You may also need to modify theMessageIdif you are attempting to export the same snapshot more than once.
- NOTE: The example content is a subset of an SNS event notification containing the minimum valid event data necessary to successfully trigger the Lambda function's execution. You should modify the
-
Click the Test button to start an export.
You can check on the progress of the export in the Exports in Amazon S3 listing. When that is finished, you can use the AWS Glue Crawler that was created for you to crawl the export, then use Amazon Athena to perform queries on the exported snapshot.
Execute npm run cdk destroy to delete resources pertaining to this example.
You will also need to delete the following manually:
- The S3 bucket that was created to store the snapshot exports.
- The CDKToolkit CloudFormation Stack created by
npm run cdk bootstrap. - The
cdktoolkit-stagingbucket-<...>bucket.
This library is licensed under the MIT-0 License. See the LICENSE file.
