Repository navigation
Cannot remove cross-stack reference in a single cdk deploy (Export/Import deadlock) #38371
Replies: 2 comments
|
This is a common problem, colloquially known as the deadly embrace problem. You can solve it by controlling the reference strength between resources: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib-readme.html#reference-strength. |
|
This is one of the most notorious and frequently encountered challenges in AWS CloudFormation and AWS CDK, often referred to as the "Deadly Embrace" or Export/Import Deadlock. To answer your core questions directly: 1. Why CDK Cannot Resolve This in a Single CloudFormation PassThe limitation is not in AWS CDK itself, but is enforced server-side by the AWS CloudFormation engine:
2. Can You Do It in a "Single Pipeline Execution"?If by "single pipeline execution" you mean a single However, you can automate it cleanly depending on how your pipeline is structured: Pattern A: The Canonical 2-Step Release (Standard Enterprise Best Practice)This is the safest zero-downtime path recommended across production environments:
Pattern B: Pipeline Staging / Ordered Step AutomationIf you want a single CI/CD run (e.g. GitHub Actions, GitLab CI, or AWS CodePipeline) to perform the entire migration automatically without manual multi-PR overhead: You can structure your CI/CD job step sequence: # 1. First, deploy ChildStack with the decouple code
cdk deploy ChildStack --require-approval never
# 2. Once ChildStack succeeds and releases the import, deploy ParentStack
cdk deploy ParentStack --require-approval never(Note: For this to work in one pipeline run, ParentStack must still synthesize the export during step 1, e.g. via Pattern C: The Architectural Solution (Escape CloudFormation Export Locks entirely)For stacks that undergo frequent refactoring or lifecycle divergence, rely on AWS Systems Manager (SSM) Parameter Store instead of direct CloudFormation Exports:
Why SSM solves this permanently: |
Uh oh!
There was an error while loading. Please reload this page.
Hi! I love cdk, thanks for this tool.
When a
ChildStackreferences an attribute from aParentStack(e.g., using a Parent resource property inside a Child's Lambda Function environment variable), AWS CDK automatically creates an implicit CloudFormation Export/Import.If I refactor the code to remove this reference by deleting the usage in theChildStackAND removing the property from theParentStacksimultaneously, cdk deploy fails. CloudFormation attempts to update theParentStackfirst (removing the exported Output) while theChildStackstill relies on it, causing a deployment blockage due to the export being in use.What is the recommended best practice to remove this cross-stack reference in a
single deploymentpipeline execution? OR the official (recommended) way to it is just apply targeting theChildStackstack alone and after a second deployment to updateParentStack?As user, I think this tool has to be smart enough to detect that is safe to delete from parent in a single deployment.
All reactions