Skip to content

CfnOutput: duplicate exportName values cause silent deployment failures #24349

Open
@alanb-sony

Description

@alanb-sony

Describe the bug

If two CDK stacks have CfnOutput with the same exportName then CDK fails with:

MyStack: creating CloudFormation changeset...

 ❌  MyStack failed: Error: The stack named MyStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at FullCloudFormationDeployment.monitorDeployment (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:344:10235)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async deployStack2 (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:347:144797)
    at async /home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:347:130251
    at async run (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:347:128257)

 ❌ Deployment failed: Error: Stack Deployments Failed: Error: The stack named MyStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at deployStacks (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:347:130558)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async CdkToolkit.deploy (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:347:146846)
    at async exec4 (/home/yoshioka/EPE/aws-serverless/node_modules/aws-cdk/lib/index.js:402:51795)

Stack Deployments Failed: Error: The stack named MyStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE

Looking in the cloudformation events you can see the error "Export with name xxx is already exported by stack yyy" it'd be nice if CDK itself reported this error.

Expected Behavior

An error on the CDK console saying "Export with name xxx is already exported by stack yyy"

Current Behavior

The stack failed to deploy with no error message

Reproduction Steps

export class MyStack1 extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    new CfnOutput(this, "Output", {
      value: "foo",
      exportName: "Output",
    });  
  }
}

export class MyStack2 extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    new CfnOutput(this, "Output", {
      value: "bar",
      exportName: "Output",
    });  
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.60.0

Framework Version

No response

Node.js Version

16

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions