Script that generates config file for website depends on CDK resource

Viewed 41

what is the most graceful way of handling when you need to generate a script that depends on CDK values/arns?

I have the following scenario:

  • All constructs are in the same stack
  • Script A depends on Construct A in CDK Stack to deploy Website A
  • Website A must be built before Constructs BCD can be deployed
  • Website A depends on Script A

Am I forced to split out the stack into stack A and B even though I only need one construct to be stood up to create the script?

Is there any automated way of doing this? Or do I need to stand up stack A, run the config gen script manually, then build the website, then stand up stack B

1 Answers

use CodePipeline. This is exactly what CodePipeline is for, to orchestrate these numerous things.

Pipeline: Deploys the stack, which has cfn.Outputs defined in it to output the values you need (Apis, secret names, whatever)

Pipeline moves those as variables and user defined parameters into a lambda in the next step, which builds your config file and drops it in an s3 or other file system for your site to then access.

You can then use a Codebuild to build and deploy your website or put a manual approval step to pause the pipeline, letting you do whatever else you need to deploy said website, then approve the pipeline to move on to stack B.

Alternatively, if you dont have to split them up for some reason, then you can use the dependsOn https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib-readme.html#construct-dependencies formats to pass it directly along to whatever constructs are building your website, assuming its all being done in CDK. The issue with this is that before deployment these are just Token representations of what will come - so if there are some delicate timings or the dependsOn gets too cluttered, its better to use CodePipeline

Related