im looking for a way to specifiy the deployment order of my stacks in my project. I know i could add dependencies, however these stacks do not depend on each other and i might want to delete some at a later time.
I have a framework of services that are needed globally for every other stack (e.g. rds). These are being deployed at the very start.
- App-Networking
- App-GlobalResources
Now i want to add stacks for new customers, these stacks will depend on the 2 global stacks, and on each other, but not on any of the other customers stacks.
E.g.
- App-Customer-A-EC2 (depends on App-Networking)
- App-Customer-A-Lambdas (depends on App-Customer-A-EC2)
- App-Customer-A-Settings (depends on App-GlobalResources, App-Customer-A-Lambdas)
and
- App-Customer-B-EC2 (depends on App-Networking)
- App-Customer-B-Lambdas (depends on App-Customer-B-EC2)
- App-Customer-B-Settings (depends on App-GlobalResources, App-Customer-B-Lambdas)
I would like all these stacks to be deployed in this order. First the global stacks, then all of customer a, then all of customer b.
However this is what cdk is doing:
- App-Networking
- App-GlobalResources
- App-Customer-A-EC2
- App-Customer-B-EC2
- App-Customer-A-Lambdas
- App-Customer-B-Lambdas
- App-Customer-A-Settings
- App-Customer-B-Settings
Which means customer A has to wait untill all other customers resources have been generated before he can use the system and so on. As there are no cross dependencies between the customer stacks, they dont have to be deployed in the order cdk does it.
So, what are my options here? Apart from adding dependencies? I thought initially it would be alphabetically ordered by stack name, or maybe by cunstruct path, but it doesnt seem so.
Thank you!
Edit: I went through the code of the cdk app and found the sorting code. There currently is no way in my case. The type of sorting used by CDK will always result in the observed pattern.
I am now working around by adding dependencies. When deleting stacks that are "in the middle" and have dependencies, i have to destroy them with the -e
argument.
aws-cdk deploy
is a stand alone deployment per stack. So even if you define multiple stacks within your root you still need to specify which stack you are deploying. For me I would create a deployment script that can check if certain deployments have already been made prior and then deploy in the order you wish. – amwill04cdk deploy *
will deploy all your stacks in the "correct" order. – Lightning303