1

I am currently working on an environment that gets destroyed every night and redeployed every morning. The CDK provides a construct named DatabaseInstanceFromSnapshot but this won't create one if there is no snapshot available.

Is there a way to check for "If a snapshot is available, use DatabaseInstanceFromSnapshot, else use DatabaseInstance"? I tried with SSM parameters but these don't get fetched until during the Cloudformation deployment (when the if/else is already parsed so the value doesn't matter of the SSM parameter)

Tom
  • 403
  • 3
  • 14
  • 1
    This is against CDK best practices. A CDK app should always synth to the same template, and not make any network calls. If you understand the risks and are willing to forgo best practices, you can, for example, use the `fromLookup` methods of your SSM parameters - these get resolved during synth, not deployment. They are then written to `cdk.context.json` to make sure all subsequent synths are the same (to follow best practices), but you can just avoid committing the context to VCS and force it to perform a lookup every time. – gshpychka Jan 21 '22 at 10:02
  • Thanks for the input, I am going to try this out. – Tom Jan 21 '22 at 10:03
  • As a similar alternative, you could check if snapshot exists by other means (e.g. aws cli) using a script and update a config json file that your CDK can be using later. Again, this also won't be considered best practice for CDK but we also keep running into these type of scenarios. – burcakulug Jun 10 '22 at 15:11

0 Answers0