Open SamStephens opened 2 years ago
Hi @SamStephens! Can you provide the cyclic dependency error that you're getting as well? Interested in understanding exactly what resources CDK thinks depend on each other. Usually with these dependencies there's some CDK magic under the hood that you never need to know about until you hit these dependency errors :), but I can dive into the source code for you and see whats up.
@kaizencc Sure thing; I'll put together a proper repro in a few days time when I'm back at work.
@kaizencc also I was interested in asking about broader design goals here. Is the infrastructure stack/code stack split pattern something that the CDK is explicitly interested in supporting?
Basically, my situation is that I'm currently exporting ARNs from my infrastructure stack and importing the resources using them into my code stack; this is the approach I'm seeing others to work around similar issues. Being able to directly share the resources between the two stacks would be cleaner; but I don't want to do it and then find myself with an issue that is considered by design and will not be resolved. I want to know that the CDK considers this is a usage pattern it supports before I move to it.
@SamStephens regarding your second question, I think you'd be better off opening a new guidance issue about it so that the question gets into the hands of the right people. My answer is that I'm not entirely sure. How are you planning on sharing resources between two stacks? I think if your plan is to use nested stacks to achieve this then that is definitely a CDK pattern we plan to support.
Thanks @kaizencc. I've updated the bug report to include a proper reproduction.
I'll open a separate guidance issue about the pattern, as you suggest. However, I am interested in using peer stacks as per the reproduction, not nested stacks. When I worked with Nested Stacks back when I was an AWS employee I found them quite clunky to work with, although this was a few years ago. I'd rather operate using peer stacks with exported using CfnOutput
and imported using Fn.import_value
, which is my current workaround for this issue.
@kaizencc I've got a proper repro here now, can you please remove the needs-reproduction tag?
Describe the bug
I want to use the classic pattern where you have an infrastructure stack and a code stack.
I define an Opensearch domain in my infrastructure stack in a VPC. I then define a code stack, and attempt to wire up a Lambda that uses that domain.
This works when all the resources are in one stack; or if the code stack is nested in the infrastructure stack. But if they're peer stacks I get a cyclic reference stack.
For the reproduction provided below, the error is:
Expected Behavior
For all the resources related to my Lambda to be defined in the Code stack, so there's no cyclic references. That's what I'd do if I was writing the Cloudformation directly.
Current Behavior
The lambda function itself is defined in the code stack Cloudformation. However, the AWS::EC2::SecurityGroupIngress allowing the lambda function ingress to the Opensearch domain is defined in the infrastructure stack Cloudformation.
Reproduction Steps
The simplest reproduction I could come up with is to generate a new python application using
cdk init app --language python
, and then update app.py to be:Possible Solution
For all the resources related to my Lambda to be defined in the Code stack, so there's no cyclic references. That's what I'd do if I was writing the Cloudformation directly.
Additional Information/Context
No response
CDK CLI Version
2.23.0 (build 50444aa)
Framework Version
2.24.0
Node.js Version
14.17.0
OS
Ubuntu (Windows Subsystem for Linux)
Language
Python
Language Version
3.9.7
Other information
No response