CloudFormation "Export ... cannot be deleted as it is in use" in CI
A cross-stack export is consumed by another stack via Fn::ImportValue. CloudFormation will not let you delete or change the value of an export while any stack still imports it.
What this error means
An update or delete fails with "Export <name> cannot be deleted as it is in use by <consumer-stack>." The producer stack cannot proceed until the dependency is broken.
An error occurred (ValidationError) when calling the UpdateStack operation:
Export my-app-VpcId cannot be deleted as it is in use by networking-consumerCommon causes
A consumer stack still imports the export
Another stack uses Fn::ImportValue on the export, so its value is locked until that import is removed.
A rename or removal changes the export
Renaming or deleting the output that backs the export is treated as deleting the export, which is blocked while it is referenced.
How to fix it
Remove the import from consumers first
- Find every stack that imports the export (the message names one).
- Update those consumer stacks to stop importing it, or point them at a new value.
- Then update or delete the producer stack.
aws cloudformation list-imports --export-name my-app-VpcIdKeep the export stable across deploys
Avoid changing the exported value during an update; introduce a new export name and migrate consumers before retiring the old one.
How to prevent it
- List imports before changing or deleting any export.
- Migrate consumers to a new export before removing the old one.
- Prefer SSM parameters over hard exports for values that change often.