Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdk destroy: No stack found in the main cloud assembly #32836

Closed
1 task done
cporte opened this issue Jan 10, 2025 · 3 comments · Fixed by #32839
Closed
1 task done

cdk destroy: No stack found in the main cloud assembly #32836

cporte opened this issue Jan 10, 2025 · 3 comments · Fixed by #32839
Labels
bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0 package/tools Related to AWS CDK Tools or CLI potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@cporte
Copy link

cporte commented Jan 10, 2025

Please add your +1 👍 to let us know you have encountered this


Status: RESOLVED

Overview:

In version 2.175.0, running cdk destroy <wildcard-pattern>, with an application not containing any stacks at the top-level assembly, but only in nested stages, fails with the following error:

No stack found in the main cloud assembly. Use "list" to print manifest

Workaround:

Downgrade to 2.174.1 or upgrade to 2.175.1, or add an unused stack directly under the App.

Solution:

Downgrade to 2.174.1 or upgrade to 2.175.1.

Related Issues:


Original issue

Describe the bug

Hello,

Since the version 2.175.0 of the CLI we can no longer run cdk destroy.

Run cdk destroy --force true 'Dev*/*'

No stack found in the main cloud assembly. Use "list" to print manifest

While cdk list does yield some result:

`cdk list` 
  
LocalStage/NetworkStack (LocalStage-NetworkStack)
DevStage/NetworkStack (DevStage-NetworkStack)

The problem is not related to the wildcard nor the specific stack naming.
(Same result with cdk destroy --all or cdk destroy 'DevStage/NetworkStack'

One specificity that might explain the issue, we are using the cdk.Stage class to organize our stacks, but we are not using the CodePipeline constructs (our CI/CD runs outside of AWS and calls the cdk commands using the wildcards)

We didn't try without this code structuration.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

2.174.1

Expected Behavior

Similar to 2.174.1 and before, it is expected to run the stack destruction for the given stacks (or all if --all is specified)

Current Behavior

the cdk destroy commands yield an error:
No stack found in the main cloud assembly. Use "list" to print manifest

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import {Construct} from 'constructs';

const devEnv = {account: 'XXXXXXXXXXXX', region: 'eu-central-1'};
const app = new cdk.App();

export class DevStage extends cdk.Stage {
  constructor(scope: Construct, id: string, props: cdk.StageProps) {
    super(scope, id, props);

    const networkStack = new NetworkStack(this, 'NetworkStack', {
      env: props.env
    });
  }
}

export class NetworkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    super(scope, id, props);

    new s3.Bucket(this, `MyBucket`, {
      autoDeleteObjects: true,
      removalPolicy: cdk.RemovalPolicy.DESTROY
    });
  }
}

new DevStage(app, 'DevStage', {env: devEnv});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.175.0

Framework Version

No response

Node.js Version

20.18.1

OS

Ubuntu 24.04

Language

TypeScript

Language Version

No response

Other information

No response

@cporte cporte added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 10, 2025
@github-actions github-actions bot added potential-regression Marking this issue as a potential regression to be checked by team member package/tools Related to AWS CDK Tools or CLI labels Jan 10, 2025
@pahud pahud self-assigned this Jan 10, 2025
@pahud pahud added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 10, 2025
@pahud
Copy link
Contributor

pahud commented Jan 10, 2025

cloud be related to #32636

let me verify.

@pahud
Copy link
Contributor

pahud commented Jan 10, 2025

I tried your code with a little bit fix

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';

const devEnv = {
  account: process.env.CDK_DEFAULT_ACCOUNT,
  region: process.env.CDK_DEFAULT_REGION
};
const app = new cdk.App();

export class DevStage extends cdk.Stage {
  constructor(scope: Construct, id: string, props: cdk.StageProps) {
    super(scope, id, props);

    new NetworkStack(this, 'NetworkStack', {
      env: props.env
    });
  }
}

export class LocalStage extends cdk.Stage {
  constructor(scope: Construct, id: string, props: cdk.StageProps) {
    super(scope, id, props);

    new NetworkStack(this, 'NetworkStack', {
      env: props.env
    });
  }
}

export class NetworkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    super(scope, id, props);

  }
}

new DevStage(app, 'DevStage', {env: devEnv});
new LocalStage(app, 'LocalStage', {env: devEnv});

deploy

% npx cdk deploy "DevStage/*" "LocalStage/*"

destroy

% npx cdk destroy --force true 'Dev*/*'     
No stack found in the main cloud assembly. Use "list" to print manifest
% npx cdk ls                                
DevStage/NetworkStack (DevStage-NetworkStack)
LocalStage/NetworkStack (LocalStage-NetworkStack)
% npx cdk --version
2.175.0 (build 703e81f)
% npx cdk destroy "LocalStage/NetworkStack"
No stack found in the main cloud assembly. Use "list" to print manifest

downgrading to 2.174.1 fixes this issue

% npx cdk destroy "LocalStage/NetworkStack"
Are you sure you want to delete: LocalStage/NetworkStack (y/n)? 

I can reproduce your case now. This seems to be a regression.

@pahud pahud removed their assignment Jan 10, 2025
@pahud pahud added cli Issues related to the CDK CLI p0 effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jan 10, 2025
rix0rrr added a commit that referenced this issue Jan 10, 2025
Reverts #32636

It leads to a problem in case of applications where there are no
top-level stacks, but only stacks in nested stages: #32836.

Closes #32836.
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2025
rix0rrr added a commit that referenced this issue Jan 10, 2025
Reverts #32636

It leads to a problem in case of applications where there are no
top-level stacks, but only stacks in nested stages: #32836.

Closes #32836.
@rix0rrr rix0rrr added the management/tracking Issues that track a subject or multiple issues label Jan 10, 2025
@rix0rrr rix0rrr changed the title cli: CDK destroy pretends no stack are found in the main cloud assembly cdk destroy: No stack found in the main cloud assembly Jan 10, 2025
@rix0rrr rix0rrr pinned this issue Jan 10, 2025
@aws aws unlocked this conversation Jan 10, 2025
rix0rrr added a commit to cdklabs/aws-cdk-notices that referenced this issue Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. cli Issues related to the CDK CLI effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0 package/tools Related to AWS CDK Tools or CLI potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants