Home > Blockchain >  How to use `cdk diff` to programmatically check whether a stack needs an update?
How to use `cdk diff` to programmatically check whether a stack needs an update?

Time:03-04

I am using CDK to deploy cf stack to AWS. It has cdk diff command to tell me what changed in this deployment. If there is nothing changed, it just shows There were no differences for each stack included in the cdk project.

I have a requirement to run different command based on whether the cdk requires a change. How can I know whether it requires a change from a script? I have checked that cdk diff return code is 0 for both change and no change. What is the right way to know whether the change-set will change anything?

CodePudding user response:

The --fail flag will cause cdk diff to exit with exit code 1 in case of a diff. Add conditional logic to handle the exit code cases:

cdk diff --fail && echo "no diffs found" || echo "diffs found"
  • Related