I found a built-in CDK method on core.Stack
that handles this exact issue:
export_value()
Link to Python CDK docs here
https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.core/Stack.html?highlight=export_value#aws_cdk.core.Stack.export_value
One of the uses for this method is to remove the relationship between two Stacks established by automatic cross-stack references. It will temporarily ensure that the CloudFormation Export still exists while you remove the reference from the consuming stack. After that, you can remove the resource and the manual export.
My example is needing to replace an old DB stack with a new one (changing from serverless to provisioned RDS).
I simply rename the old DB stack variable name and below it add the following:
self.export_value(old_cluster.cluster_identifier)
Within export_value()
I pass in the exported output value that was causing the dependency issue. I can either hardcode it as a string or better yet can find where it is getting it from and reference that instead, in this case the value was from cluster_identifier
.
After the stack has been updated I can remove the old DB cluster and this export_value()
line.