4

I have my production infrastructure deployed via CDK pipelines.CodePipeline. This is a CDK construct that uses AWS CodePipeline service to deploy CDK apps.

Since this is fully managed, I don't need to put cdk deploy command in the pipeline stage, and it automatically builds it for me.

Unfortunately, it doesn't seem to have an option to disable auto-rollback. Does it?

My code:

from aws_cdk import pipelines

# ... builds cdk synth

pipeline = pipelines.CodePipeline(
    self,
    "Pipeline",
    cli_version=Toolchain._get_cdk_cli_version(),
    cross_account_keys=True,
    docker_enabled_for_synth=True,
    publish_assets_in_parallel=False,
    synth=synth,
)
production = cdk.Stage(
    pipeline,
    PRODUCTION_ENV_NAME,
    env=cdk.Environment(account=PRODUCTION_ENV_ACCOUNT, region=PRODUCTION_ENV_REGION),
)
Backend(
    production,
    constants.APP_NAME + PRODUCTION_ENV_NAME,
    env=cdk.Environment(account=PRODUCTION_ENV_ACCOUNT, region=PRODUCTION_ENV_REGION),
    stack_name=constants.APP_NAME + PRODUCTION_ENV_NAME,
    github_branch="production",
    image_tag="prod",
)
pipeline.add_stage(production)

2 Answers 2

1

This is not possible with CDK Pipelines. It does not use the CDK CLI (which has the --no-rollback flag) for deployment, instead using CodePipeline's integration with CloudFormation, which does not support disabling rollback. Here is the documentation on the available configuration options for CloudFormation actions in CodePipeline: https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CloudFormation.html#action-reference-CloudFormation-type

And here is the relevant configuration options in CDK:

If useChangeSets is set to true: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CloudFormationCreateReplaceChangeSetAction.html Otherwise: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CloudFormationCreateUpdateStackAction.html

So you would not be able to achieve this even with escape hatches.

-1

It looks like you should be able to do it by setting the rollback option in your cdk.json file:

rollback: If false, failed deployments are not rolled back.

The guide for CI/CD with CDK Pipelines says:

Be sure to commit your cdk.json and cdk.context.json files to source control.

So I'm pretty sure these options will also be used when deploying through the pipeline.

1
  • 1
    They won't be used in the pipeline, since the pipeline doesn't use cdk deploy, it creates and executes the changeset using the cloudformation API.
    – gshpychka
    Commented Oct 13, 2023 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.