I am using nodejs cdk to create my stack.
I have a RDS instance:
this.database = new cdk.aws_rds.DatabaseInstance(this, `${id}_db`, {
removalPolicy: cdk.RemovalPolicy.SNAPSHOT,
....,
})
But I want to restore the database to a previous snapshot. I found that I can change it to:
this.database = new cdk.aws_rds.DatabaseInstanceFromSnapshot(this, `${id}_db`, {
removalPolicy: cdk.RemovalPolicy.SNAPSHOT,
....,
})
with some minor alterations which does recover the database. I want to be able to keep my cdk unchanged though. I don't want to have to alter my cdk everytime I do a restore.
I considered using a manual restore through the cli, thinking it would update the existing instance but it doesn't; it creates a new instance. I was expecting a simple way of making my existing cdk script (with new DatabaseInstance()) recognise the new instance and treat that as though it is the original one. And then I was hoping I could just delete the old instance seamlessly.
I was under the impression that a cdk script is supposed to be an immutable blueprint of your backend stack; you write your cdk once and then, so long as you don't want to change your architectural design, you don't have to touch your cdk. Following that design philosophy, aws cdk should have a mechanism to automatically detect recoveries and treat the new recovery as though it was the original instance without having the later alter the cdk.
I suppose it does, in the form of DatabaseInstanceFromSnapshot, but what is unclear to me is whether, once I have done a recovery, if I should keep DatabaseInstanceFromSnapshot permanently? Or if/how I should try to go back to using DatabaseInstance()?
- Is there any drawback to using DatabaseInstanceFromSnapshot? (I looked at Is it safe to use rds.DatabaseInstanceFromSnapshot long term? but didn't understand)
- Should i use DatabaseInstanceFromSnapshot for my production code long term?
- Or, should I try to get back to using DatabaseInstance once the snapshot has been used?
- And, if 3. is true, what is the standardised procedure for making aws cdk recognise the new instance as though it were the old one.