CDK construct to periodically take snapshots of RDS databases, sanitize them, and share with selected accounts.
Project description
CDK Construct for RDS Sanitized Snapshots
Periodically take snapshots of RDS databases, sanitize them, and share with selected accounts.
Use this to automate your development and/or QA database creation, instead of forcing them to use a database that was created last year and was kind of kept in shape by random acts of kindness. Developers and QA love real data and this lets you create non-production databases with sanitized production data. Use the sanitization step to delete passwords, remove credit card numbers, eliminate PII, etc.
See Constructs Hub for installation instructions and API in all supported languages.
Overview
This project supplies a CDK construct that sets up a step function and a timer to execute this function. The function will create a sanitized snapshot of a given database and share it with configured accounts. Those accounts can then create new databases from those snapshots.
The step function does the following to create the snapshot:
-
Get a snapshot of the given database by either:
- Finding the latest snapshot for the given database
- Creating and waiting for a new fresh snapshot
-
Re-encrypt snapshot if KMS key is supplied
-
Create a temporary database from the snapshot
-
Wait for the database to be ready
-
Reset the master password on the temporary database to a random password
-
Wait for the password to be set
-
Use a Fargate task to connect to the temporary database and run configured SQL statements to sanitize the data
-
Take a snapshot of the temporary database
-
Optionally share the snapshot with other accounts (if you have separate accounts for developers/QA)
-
Delete temporary database and snapshot
Usage
-
Confirm you're using CDK v2
-
Install the appropriate package
-
pip install cloudsnorkel.cdk-rds-sanitized-snapshots
-
npm i @cloudsnorkel/cdk-rds-sanitized-snapshots
-
<dependency> <groupId>com.cloudsnorkel</groupId> <artifactId>cdk.rds.sanitized-snapshots</artifactId> </dependency>
-
go get github.com/CloudSnorkel/cdk-rds-sanitized-snapshots-go/cloudsnorkelcdkrdssanitizedsnapshots
-
dotnet add package CloudSnorkel.Cdk.Rds.SanitizedSnapshots
-
-
Use
RdsSanitizedSnapshotter
construct in your code (starting with default arguments is fine)
Code Sample
let vpc: ec2.Vpc;
let databaseInstance: rds.DatabaseInstance;
new RdsSanitizedSnapshotter(this, 'Snapshotter', {
vpc: vpc,
databaseInstance: databaseInstance,
script: 'USE mydb; UPDATE users SET ssn = \'0000000000\'',
})
Encryption
The new snapshot will be encrypted with the same key used by the original database. If the original database wasn't encrypted, the snapshot won't be encrypted either. To add another step that changes the key, use the KMS key parameter.
See AWS documentation for instructions on giving other accounts access to the key.
Troubleshooting
- Check the status of the state machine for the step function. Click on the failed step and check out the input, output and exception.
Testing
npm run bundle && npm run integ:default:deploy
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cloudsnorkel_cdk_rds_sanitized_snapshots-0.1.3.tar.gz
.
File metadata
- Download URL: cloudsnorkel_cdk_rds_sanitized_snapshots-0.1.3.tar.gz
- Upload date:
- Size: 93.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03500e87db502111b0ea29db85c312d3f21ed304fc93948b7444b2add9378eeb |
|
MD5 | 1501ab15f1b8ba7a8fa172e90e329159 |
|
BLAKE2b-256 | a727be11f5e1eaa040118728ce258f77cede6db3d21b67d84054f98659595e9c |
File details
Details for the file cloudsnorkel.cdk_rds_sanitized_snapshots-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: cloudsnorkel.cdk_rds_sanitized_snapshots-0.1.3-py3-none-any.whl
- Upload date:
- Size: 92.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eed41c1005c3f06cffef14cb98187d9f98a925c0559ffb5874db2c0bb3275f6 |
|
MD5 | 6453d13e4a61b39cacbba217105fae6d |
|
BLAKE2b-256 | 0dd40e5bf8d5ea60f036f64203b3f9f4cb7164781933aaf77a487869838a9d6c |