1

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()?

  1. Is there any drawback to using DatabaseInstanceFromSnapshot? (I looked at Is it safe to use rds.DatabaseInstanceFromSnapshot long term? but didn't understand)
  2. Should i use DatabaseInstanceFromSnapshot for my production code long term?
  3. Or, should I try to get back to using DatabaseInstance once the snapshot has been used?
  4. 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.
1
  • For most production cases creation is a one time step. Does your use case involves creating or restoring database regularly? Can you share the exact use case please. Commented Aug 16, 2024 at 4:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.