Skip to content
Latchkey

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.

CloudFormation
An error occurred (ValidationError) when calling the UpdateStack operation:
Export my-app-VpcId cannot be deleted as it is in use by networking-consumer

Common 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

  1. Find every stack that imports the export (the message names one).
  2. Update those consumer stacks to stop importing it, or point them at a new value.
  3. Then update or delete the producer stack.
Terminal
aws cloudformation list-imports --export-name my-app-VpcId

Keep 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.

Frequently asked questions

What causes ""cannot be deleted as it is in use""?
Another stack uses Fn::ImportValue on the export, so its value is locked until that import is removed.
How do I fix "cannot be deleted as it is in use"?
Remove the import from consumers first

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card