Search code examples
amazon-web-servicesaws-cloudformationaws-cdk

Deleting Resources in a Multi-Stack Environment where Outputs are passed


How to get rid of a resource in CDK when one of its outputs was passed between Stacks?

The actual scenario looks like this:

  • StackA creates two resources X and Y
  • StackB references the ARNs of X and Y (so StackA has two Exports: X-ARN & Y-ARN)

Now I want to get rid of X. If I do that, I will get the 'Cannot delete export' error as StackB relies on the X-ARN export.

As the Output is auto-generated as CDK detects the dependency and I can never change the update order (as StackB still relies on StackA due to Y-ARN), I'm in a deadlock now?

Maybe I'm getting something incorrectly here, but this seems like a very common scenario.

If I'd have used a manually created CfnOutput, I could just switch to a placeholder value and remove the Output in a second step, but it's too late for this now.


Solution

  • You can remove the dependency from StackB and deploy it using:

    cdk deploy -e StackB
    

    Once done, you can remove the resource from StackA.

    -e:

    --exclusively, -e BOOLEAN Only deploy requested stacks and don't include dependencies.