aws-cdk: [CLI]package/tools: Force deploy flag does not work

Running cdk deploy stack-name --require-approval never --force does not work. Specifically its skips updating the stack with (no changes) outputted in the command line. I’ve also tried the following patterns:

  • cdk deploy stack-name --force
  • cdk deploy --force stack-name

Reproduction Steps

Repo is private so cannot link but simply running one of the above commands with cdk toolkit version 1.108.0 should suffice. I can try and reproduce in a public repo if the person seeing this cannot reproduce.

What did you expect to happen?

CDK would never skip updating stacks due to “no changes” in the template when the --force flag is passed.

What actually happened?

CDK skips updating stacks due to “no changes” in the template when the --force flag is passed.

Environment

  • **CDK CLI Version: ** 1.108.0
  • Framework Version: 1.108.0
  • Node.js Version: v12.22.0
  • OS : MacOs Big Sur
  • Language (Version): TS 4.2.4

Other

 ✅  service-name (no changes)

This is 🐛 Bug Report

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 20
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

cdk deploy --force should force cloudformation to redeploy without consider the change-sets.

I have tested it. A codepipeline is created by my cdk project. Then I add a step manually in the codepipeline, and redeploy cdk project to force it change back to the defined stage. However, cdk deploy --force is not working as expected. From cloudformation point of view, nothing is change. That’s mean, this --force option is helpless.

I agree with @jefftham , we should be able to overwrite the Cloudformation rule using --force, to literally force to deploy.

@Lockoo You only need to add --require-approval never as argument after cdk deploy. If you want more option type cdk deploy --help and search the option --require-approval

any updates on this? it’s a really annoying issue that this flag doesn’t actually work

Hi everyone on this issue,

Please run the command again with -v:

cdk deploy --force -v

And observe the additional logged output.

  • If the message says skipping deployment (use --force to override), then CDK has short-circuited the deployment because it thinks there is nothing to do. It is usually right, but there might be cases in which it is wrong, and you can use --force to force it to update.
  • If you see the text No changes are to be performed on <STACK>, then CloudFormation considers the change to have no effects, and in fact if we had told CloudFormation to execute it would have given us back an error. There is just nothing to do for CloudFormation, and CDK cannot change that fact.
  • If you see neither of these messages, then let me know what messages you do see.

If you are planning to use --force to wipe away drift (that is: you’ve changed resources out-of-band, and now want to get them back into the state as declared in the template), then be aware: this is not possible. CloudFormation does not support wiping away drift in this matter. It exclusively operates on its own view of the world which it has built up over deployments done via CloudFormation, and it will not look at operations done in the mean time via the console or the CLI. If this is what you want to do, you need to look at the CloudFormation Drift Detection feature.

I have the same use case - I want cdk deploy to re-deploy the stack even if there are no changes in the CFN template. My stack just simply builds a docker container and uploads it to ECR - while the Dockerfile itself doesn’t change, the dependencies that it will be pulling via pip will be updated, so I want it to re-build.

I found https://github.com/aws/aws-cdk/issues/8493 which claims that you can do this with cdk deploy --method direct, but this didn’t work for me (nor did cdk deploy --force).