question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[cdk-pipelines] Stacks in stage doesn't get deployed in parallel when stage.add_application is used?

See original GitHub issue

❓ Parallel Deployment to Multiple Accounts

The Question

[1]: CDK Pipeline does not deploy the a stack in two accounts in parallel

environments = self.node.try_get_context("environments")
stage = pipeline.add_stage("dev")
stage.add_application(EpsRoute53(self, f"dev01-route53", env=environments["dev01"], account_identifier="dev01"))
stage.add_application(EpsRoute53(self, f"dev02-route53", env=environments["dev02"], account_identifier="dev02"))

Note, environments[“dev01”], - account, region combination

Result: The stack EpsRoute53 is getting ordered as follows

  1. dev01-epsroute53.prepare
  2. dev01-epsroute53.deploy
  3. dev02-epsroute53.prepare
  4. dev02-epsroute53.deploy

I had to change to using something like this to get it added pipeline stage actions in parallel.

environments = self.node.try_get_context("environments")
stage = pipeline.add_stage("dev")
stage.add_actions(pipelines.DeployCdkStackAction(action_role=iam.Role.from_role_arn(self, id="role-dev01",role_arn="arn:aws:iam::<account-dev01>:role/<pipeline-role-arn>"),
                                   stack_name="dev01-route53-domain-stack",
                                   template_path="<path of the template>",
                                   region="us-west-2",
                                   cloud_assembly_input=cloud_assembly_artifact,
                                   prepare_run_order=1,
                                   execute_run_order=2,
                                   cloud_formation_execution_role=iam.Role.from_role_arn(self, id="role-dev01a",
                                   role_arn="arn:aws:iam::<account-dev01>:role/cdk-XXXX-cfn-exec-role-<account-dev01>-us-west-2")
                                   )))
stage.add_actions(pipelines.DeployCdkStackAction(action_role=iam.Role.from_role_arn(self, id="role-dev01",role_arn="arn:aws:iam::<account-dev02>:role/<pipeline-role-arn>"),
                                   stack_name="dev02-route53-domain-stack",
                                   template_path="<path of the template>",
                                   region="us-west-2",
                                   cloud_assembly_input=cloud_assembly_artifact,
                                   prepare_run_order=1,
                                   execute_run_order=2,
                                   cloud_formation_execution_role=iam.Role.from_role_arn(self, id="role-dev02a",
                                   role_arn="arn:aws:iam::<account-dev02>:role/cdk-XXXX-cfn-exec-role-<account-dev02>-us-west-2")
                                   )))

Is this an expected behavior?

Environment

  • CDK CLI Version: 1.60.0 (build 8e3f53a)
  • Module Version: 1.60.0
  • Node.js Version: v12.18.2
  • OS: CentOS Linux release 7.8.2003 (Core)
  • Language (Version): Python 3.7.9

Other information

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kichikcommented, Dec 8, 2020

The workaround we ended up using is:

def _run_next_action_in_parallel(stage: Stage):
    current_run_order = stage.next_sequential_run_order(0)  # passing 0 means it doesn't advance the run oder
    stage.next_sequential_run_order(1 - current_run_order)  # send the order back to 1 so the next stage runs in parallel

 
stage.add_application(EpsRoute53(self, f"dev01-route53", env=environments["dev01"], account_identifier="dev01"))
_run_next_action_in_parallel(stage)
stage.add_application(EpsRoute53(self, f"dev02-route53", env=environments["dev02"], account_identifier="dev02"))
_run_next_action_in_parallel(stage)

It resets the run order after each application and allows them to run in parallel.

1reaction
karthikns16commented, Sep 21, 2020

@rix0rrr , Thank you for reviewing my request. Any tentative of ETA on when we could get this feature added?

Even with run order say if I had two accounts, the action in runOrder 1 has to be successful for both the accounts for action in subsequent order to start. Instead of stopping the whole pipeline when a deployments fails in one of the many accounts, shouldn’t it stop just the deployment just in that one account and push forward in the remaining accounts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Continuous integration and delivery (CI/CD) using CDK ...
CDK Pipelines are self-updating. If you add application stages or stacks, the pipeline automatically reconfigures itself to deploy those new stages or ...
Read more >
Deploy stacks in parallel with AWS CDK Pipelines
For the deployment of the first application, it does two actions in the stage; "prepare" and "deploy". These are linked to "RunOrder: 1"...
Read more >
AWS CDK Pipeline: Assets stage fails to find buildSpec ...
We are trying to get our multi-stack application deployed using the cdk pipeline library. We have recently disabled the ...
Read more >
Production-Ready CDK - CDK Pipelines - Luminis
Don't use 'cdk deploy' in your pipelines ... import { Stack, StackProps, Stage } from 'aws-cdk-lib'; import { CodePipeline, ...
Read more >
DEPLOY YOUR APPLICATION TO AWS USING CDK ...
For deploying your application to the cloud you will be using AWS CDK Pipelines. CDK Pipelines are a high level construct from CDK...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found