Maintain auto-generated outputs/exports when referencing resources in others stacks.
See original GitHub issueMaintain auto-generated outputs/exports when referencing resources in others stacks.
Use Case
In order to improve code readability, avoid zombies resources, and ease the deploy process in the pipeline
As a devOps
I want to be able to maintain the output/export, after not being used. (the output
that gets generated when I reference a resource created in other stack)
Proposed Solution
Have an attribute that let us keep the output/export in order to be able to “remove” the reference of the resource but not the output/export, and not fail at deploy time. (almost the same way the retention policy works)
Other
The deployment process seems to be the following: 1st. Synth the template, 2nd. Removes the resources that changed in a way they have to be replaced/recreated, 3rd. Recreates/creates the resources needed, 4th. Replaces the needed references. 5th. The rest of the steps. or so it seems.
For example:
Version 1:
API GW method XYZ
(stack 1) -> ALambda
(stack 2) (this creates an output
for ALambda
)
Version 2:
API GW method XYZ
(stack 1) -> AnotherLambda
(stack 2) (this creates an output
for AnotherLambda
but “erases” the ALambda
output
because is not being used, failing at deploy time either way) because it would still point to the old ALambda
name
In this example fails in the hypothetical 2nd step.
In the proposal I think the deployment process wouldn’t change at all and we could avoid de deployment problem.
Our specific problem was that we changed the name of a lambda function that was in a stack and was referenced by APIGateway in another stack. Throwing this error:
Export APIStackExampleStack123456:APIStackExampleStackExportsOutputFnGetAttStepFunctionInvokerABE843C6Arn8B082DE7 cannot be deleted as it is in use by APIStack213522BF
Which is clear but that give us a constraint in the pipeline.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
PS: This wouldn’t go against the design system of CloudFormation because is the same concept the DeletionPolicy.RETAIN
resource property have.
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 4 years ago
- Reactions:16
- Comments:11 (1 by maintainers)
@skinny85 made a cool post working this thing around!
https://www.endoflineblog.com/cdk-tips-03-how-to-unblock-cross-stack-references
If your CDK version is grater than 1.90.1 you can do:
this.exportValue(bucket.bucketArn);
wherethis
is theStack
instance.I was able to create a workaround, in the same spirit of the proposed workaround at https://github.com/aws/aws-cdk/issues/5819#issuecomment-643821627, but I don’t need the full logical id that CDK generates.
I create a
GcStack
, which “holds” dummy resources:And then using it:
This creates a stack named
GcStack
that only containsCustom:Null
resources which reference the resources fromstack_with_resources
. You don’t need to deploy theGcStack
, but I think it doesn’t hurt if you deploy it (I haven’t tested though).With this workaround you can reference resources across many many accounts/environments without having to go through all of the outputs that each account/environment generate.
I hope this helps someone.