aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Deploy stacks in parallel where possible

Open nathanpeck opened this issue 7 years ago • 52 comments

I am deploying a CDK app that uses 9 different stacks. Many of the stacks either do not depend on each other, or can be deployed in parallel. For example one base stack that has a DynamoDB table needs to be deployed first, but then all five stacks which have a Lambda that uses that table could be deployed in parallel. Then finally a stack that creates the API gateway that points at those Lambda functions can be deployed.

Ideally I would like to be able to opt in to deploying stacks concurrently as much as possible. Right now CDK only ever deploys one stack at a time, which makes the overall cdk deploy much slower than it needs to be.

nathanpeck avatar Mar 07 '19 19:03 nathanpeck

Second that. It is very time-consuming even on relatively small projects.

dnagir avatar Mar 11 '19 16:03 dnagir

Would be super useful, but I guess it's not easy to implement because there are also a few number of limitations in terms of what can happen concurrently in an account/region, such as:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-api

& more, see: https://twitter.com/danbdo/status/1110183888415002624?s=19

lusentis avatar Mar 25 '19 09:03 lusentis

@eladb This would be amazing. Any thoughts/plans on this?

AlexCheema avatar Jul 09 '19 03:07 AlexCheema

Bumping this, we have so many stacks that without this we would likely have to utilize some sort of wrapper for the CDK which would diminish some of the value.

sd0408 avatar Jul 30 '19 16:07 sd0408

@lusentis I don't believe that concurrency limits will impact the development of this feature from the point of view of CDK, because CloudFormation already handles that concurrency internally. From CDK's perspective it would just be deploying multiple CloudFormation stacks in parallel and waiting for CFN to come back with a success status. CFN already handles the retries / concurrency internally when it is deploying multiple stacks at once

nathanpeck avatar Oct 24 '19 14:10 nathanpeck

I've got some environments with 30 or 40 stacks, so this would be very helpful.

winjer avatar Nov 01 '19 10:11 winjer

we also have a huge infrastructure. If we could execute the stacks parallelly it would save couple of hours' time.

Pritij avatar Jan 15 '20 12:01 Pritij

I have multiple independent stacks which manage cloudfront distributions. Updating cloudfront distribution usually takes 5-10 minutes…

Currently I work around the limitation by opening multiple terminal sessions and deploying single stack per terminal session, but hence in parallel.

muhqu avatar Mar 04 '20 15:03 muhqu

Very necessary feature. With other deployment tools is possible, for example Sceptre

enricopesce avatar Apr 29 '20 14:04 enricopesce

Especially painfull, as issue https://github.com/aws/aws-cdk/issues/5637 blocks implementing workaround for this one.

erik-sab avatar May 21 '20 07:05 erik-sab

+1, would save us significant deploy time as well.

jacques- avatar Jun 29 '20 12:06 jacques-

Already painful experience with the same stack and different environments...

OperationalFallacy avatar Jul 24 '20 12:07 OperationalFallacy

@OperationalFallacy With the same stack and different environments its not too bad because you can just run multiple copies of CDK in parallel with different profiles, or different CDK_DEFAULT_ACCOUNT env variable.

Something like this:

cdk deploy --profile dev --require-approval=never &
cdk deploy --profile production --require-approval=never &

This assumes you have two different AWS credential profiles setup, and are using two different AWS subaccounts for a developer environment and a production environment (this is best practice anyway). The & operator causes CDK to run in the background, so both instances of CDK will deploy to their respective environments in parallel.

In general I do agree that deploying to multiple environments concurrently as well as multiple stacks concurrently would be nice though

nathanpeck avatar Jul 24 '20 16:07 nathanpeck

I'm using a CloudFront factory CDK pattern that updates 10+ CF distros (separate stacks) sequentially. It takes forever to push even simple changes. Therefore this would be a great improvement if we can parallelize cdk deploy.

In the meantime, I'm tempted to run cdk list and then simply fire off individual stacks. i.e. for stack in $(cdk list); do cdk deploy $stack --require-approval=never &; done;

Edit: I'll be exploring CDK pipelines to deploy in parallel.

robertd avatar Aug 01 '20 02:08 robertd

+1

We have over 200 stacks and deploying some of them in parallel would help us a lot.

laimonassutkus avatar Oct 01 '20 12:10 laimonassutkus

We are not planning to support this in the foreseeable future. I would highly recommend looking into CDK pipelines to deploy multiple stacks in parallel.

eladb avatar Oct 01 '20 14:10 eladb

Is CDK pipelines a product or something? Or you’re saying creating a pipeline to deploy inparallel?

OperationalFallacy avatar Oct 01 '20 21:10 OperationalFallacy

I believe Elad was referring to this @OperationalFallacy : https://docs.aws.amazon.com/cdk/api/latest/docs/pipelines-readme.html

skinny85 avatar Oct 01 '20 22:10 skinny85

Thanks @skinny85, that looks like something really cool, but I can't wrap my head around it. Is there a blog post or other resources for it?

OperationalFallacy avatar Oct 01 '20 23:10 OperationalFallacy

Thanks @skinny85, that looks like something really cool, but I can't wrap my head around it. Is there a blog post or other resources for it?

Check this out: https://www.youtube.com/watch?v=774leNpQXo0

skyrpex avatar Oct 02 '20 06:10 skyrpex