How to manage a RDS Database including recovery from snapshots in CDK

Viewed 313

I am managing an RDS Database in an CDK Project. From time to time it is necasary to recover an old state of the database from snapshot.

To make this possible, I have CDK Context Parameter specifying the Snapshot from which the Database should be recovered. If it is given, the snapshot is bassed to the RDS Construct. This leads to a replacement of the database (which is fine).

Now, if the database has been recovered from snapshot and I do some other update in the CDK Project and want to update the project (which is done via CD Pipeline) I usally start the update without giving any snapshot. This leads to the database to be replaced by an empty one, which is of course not what I want.

To summarize, this is how it currently works:

Current state of the stack Deployment Paramter Result
Not created from snapshot No snapshot DB is not replaced
Not created from snapshot snapshot DB is replaced
created from snapshot No snapshot DB is replaced
created from snapshot snapshot (same) DB is not replaced
created from snapshot snapshot (different) DB is replaced

This is IMHO not managable.

But what I want is something like this:

Current state of the stack Deployment Paramter Result
Not created from snapshot No snapshot DB is not replaced
Not created from snapshot snapshot DB is replaced
created from snapshot No snapshot DB is not replaced
created from snapshot snapshot (same) DB is replaced
created from snapshot snapshot (different) DB is replaced

Or, to put it in other words:

  • If I specify no snapshot, don't replace the DB
  • If I specify a snapshot, repalce the DB

Is this possible? Or is there another good way to manage an RDS Database using CDK?

0 Answers
Related