aws-cdk: aws-cdk: direct deploy return error when there are no stack updates

Describe the bug

Using cdk deploy --method=direct when there are no stack updates:

  • On a stack that resolves SSM parameters (during deployment).

It return ❌ Deployment failed and exit code 1.

Compared to cdk deploy that return ✅ HelloCdkStack (no changes) and exit code 0.

Expected Behavior

cdk deploy --method=direct
  • Message: ✅ HelloCdkStack (no changes)
  • Exit code: 0

When there are no updates.

Current Behavior

cdk deploy --method=direct

Debug output:

HelloCdkStack: some parameters come from SSM so we have to assume they may have changed
HelloCdkStack: deploying...
HelloCdkStack: updating stack...
Call failed: updateStack({"StackName":"HelloCdkStack", ...}) => No updates are to be performed. (code=ValidationError)

Result:

 ❌  HelloCdkStack failed: Error [ValidationError]: No updates are to be performed.
    at Request.extractError (/hello-cdk/node_modules/aws-sdk/lib/protocol/query.js:50:29)
    at Request.callListeners (/hello-cdk/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/hello-cdk/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/hello-cdk/node_modules/aws-sdk/lib/request.js:686:14)
    at Request.transition (/hello-cdk/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/hello-cdk/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /hello-cdk/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/hello-cdk/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/hello-cdk/node_modules/aws-sdk/lib/request.js:688:12)
    at Request.callListeners (/hello-cdk/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'ValidationError',
  time: 2022-11-29T12:11:36.798Z,
  requestId: 'f2b0b91f-c7a9-4707-a71b-d015f4283d55',
  statusCode: 400,
  retryable: false,
  retryDelay: 843.8278571993974
}

 ❌ Deployment failed: Error: Stack Deployments Failed: ValidationError: No updates are to be performed.
    at deployStacks (/hello-cdk/node_modules/aws-cdk/lib/deploy.ts:61:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at CdkToolkit.deploy (/hello-cdk/node_modules/aws-cdk/lib/cdk-toolkit.ts:338:7)
    at initCommandLine (/hello-cdk/node_modules/aws-cdk/lib/cli.ts:364:12)

Stack Deployments Failed: ValidationError: No updates are to be performed.

Exit code: 1

Reproduction Steps

Modified sample app:

mkdir hello-cdk
cd hello-cdk
npx aws-cdk@2.x init sample-app --language typescript

Modify stack:

import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as ssm from "aws-cdk-lib/aws-ssm";

export class HelloCdkStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    ssm.StringParameter.valueForStringParameter(this, "/foo/bar");
  }
}
aws ssm put-parameter --name /foo/bar --value hello

Deploy first time:

cdk deploy --method=direct

Second time (no updates):

cdk deploy --method=direct

Possible Solution

Check if this.cfn.updateStack in directDeployment() return “no updates to be performed”-ValidationError then return noOp: true.

Additional Information/Context

It works as expected on stacks that doesn’t resolve SSM parameters.

CDK CLI Version

2.53.0 (build 7690f43)

Framework Version

2.53.0

Node.js Version

v16.18.1

OS

Mac OS

Language

Typescript

Language Version

No response

Other information

We would like to use this nice new direct deploy feature #22079 👏 in our CI/CD process, and it would therefor be nice if it doesn’t return error when there are no updates.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Awesome, thanks for letting us know @ChrisSargent !

I’ve tried it with my reproduction scenario and it is now working as intended when upgraded to CDK 2.118.0. 🎉

Closing this, resolved by: https://github.com/aws/aws-cdk/pull/28523 and released in v2.118.0

@otaviomacedo could you please share: is there an ETA for this issue?

Just ran into this trying to speed up the deployment of a large project (100s of stacks) by avoiding ChangeSet creation.

Started to experience this issue when deploying only DynamoDB tables stack after bumping: aws-cdk-lib from 2.87.0 to 2.88.0. When the stack has no changes, this cli cmd fails:

cdk deploy --method=direct

with:

STACK_NAME_HERE failed: Error [ValidationError]: No updates are to be performed

{
  code: 'ValidationError',
  time: 2023-07-23T10:33:54.575Z,
  requestId: '13368caf-1f89-4761-a37f-20ee12c38a6f',
  statusCode: 400,
  retryable: false,
  retryDelay: 631.5026618550738
}

Okay as far as I can see, I think this is the problem:

From: https://github.com/aws/aws-cdk/blob/33c820b2fe16e34d52e71bed7e1ef598f62f0bd2/packages/aws-cdk/lib/api/deploy-stack.ts#L366

    switch (deploymentMethod.method) {
      case 'change-set':
        return this.changeSetDeployment(deploymentMethod);

      case 'direct':
        return this.directDeployment();
    }

But only changeSetDeployment uses the changeSetHasNoChanges function which kind of suppresses the error, from here: https://github.com/aws/aws-cdk/blob/33c820b2fe16e34d52e71bed7e1ef598f62f0bd2/packages/aws-cdk/lib/api/util/cloudformation.ts#L290, added in this PR by @rix0rrr.

So seems like some of that code should be reused in the directDeployment function.