aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.85k forks source link

CfnOutput: duplicate exportName values cause silent deployment failures #24349

Open alanb-sony opened 1 year ago

alanb-sony commented 1 year ago

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

gshpychka commented 1 year ago

This is tricky - what if we only synth one of the stacks?

alanb-sony commented 1 year ago

I don't know how this is implemented internally, I'm not expecting CDK to do something to fix the error or detect it before deployment but it'd be nice if it caught the error from cloud formation

gshpychka commented 1 year ago

Oh, I see. I did not read the issue closely and misunderstood what you meant. Sure, getting the error from CloudFormation would be useful. I don't think calling this failure "silent" is fair, though - you get an error message.

pahud commented 1 year ago

Agree. It would be great if CDK can throw this error before CFN deployment.