AWS CDK: Avoiding CDK stack dependency errors on updates

Have you encountered an error such as the one below?

Export my-stack-1:ExportsOutputRefMyResource6724B74E921810D3 cannot be deleted as it is in use by my-stack-2

This is because:

  • A resource created by has created an export
  • is using this export in one of it’s resources
  • You are attempting to change or remove the resource in, altering the export

How can this error be worked around?

One method would be to tear down my-stack-2, update my-stack-1, then re-deploy my-stack-2. This would be slow and is not a good solution.

A better solution is provided in this GitHub issue.

#Deploy only my-stack-2, removing updating or removing the dependency
cdk deploy -e my-stack-2
#Deploy all stacks, creating the new output and updating my-stack-2 again with the correct output

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.