-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lambda] Cannot avoid circular dependency when lambda and cloudwatch-events resources are in different stacks #10942
Comments
…a different stack The Lambda Permission resource causes a cyclic dependency when the rule is in a seprate stack from the lambda target for the rule. (a picture is worth a thousand words) ``` +-------------------+ +---------------+ |Lamda Stack | |Event Stack | | | | | | +----------+ | | +------+ | | | | | | | | | | | Function |<-----------------+ Rule | | | | | | | | | | | +----------+ | | +------+ | | ^ | | ^ | | | | | | | | +-----+------+ | | | | | | | | | | | | | Permission +--------------------+ | | | | | | | | +------------+ | | | | | | | +-------------------+ +---------------+ ``` The fix is to move the Permission resource into the event stack instead. fixes #10942
Thanks for filing this issue. I've posted a fix here - #11217 |
…a different stack (#11217) The Lambda Permission resource causes a cyclic dependency when the rule is in a seprate stack from the lambda target for the rule. (a picture is worth a thousand words) ``` +-------------------+ +---------------+ |Lamda Stack | |Event Stack | | | | | | +----------+ | | +------+ | | | | | | | | | | | Function |<-----------------+ Rule | | | | | | | | | | | +----------+ | | +------+ | | ^ | | ^ | | | | | | | | +-----+------+ | | | | | | | | | | | | | Permission +--------------------+ | | | | | | | | +------------+ | | | | | | | +-------------------+ +---------------+ ``` The fix is to move the Permission resource into the event stack instead. fixes #10942 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
This change actually breaks cross-account deployments, specifically when the Rule is in one account and the lambda is in another, because then the Event stack contains resources in 2 different accounts. See #13568. I think we need to come up with a different solution to the circular-dependency problem reported by the OP. |
From v1.68.0, it became impossible to avoid circular dependencies in certain cases.
The cases are for example:
I assume this PR #10622 introduced this behavior, but not sure.
Reproduction Steps
Define two stacks as below.
One is a stack which defines a lambda function.
Another is a stack which defines CloudWatch event to invoke the lambda repeatedly.
And run
cdk synth
What did you expect to happen?
Before v1.68.0, the error below happens.
To avoid this error, as it was an only work-around I know, you can pass the reference of the lambda function retrieved by
fromFunctionArn
.So uncommenting the line in the above code resolved this problem and
cdk synth
passes successfully.What actually happened?
From v1.68.0, unfortunately, the reference of the lambda also creates circular dependencies.
So whether we use the actual lambda function or the reference of it, the same error below happens.
There's no possible work-around I found so far.
Environment
Other
This composition of stacks are commonly used in our production environment, because there're many cases that several stacks share the same lambda function.
Rather than defining a lambda function in several stacks duplicately, we'd like to define it in a single stack and referring to it from other stacks.
It'll be great if you provide us with a option which enables the previous behavior of lambda reference. (maybe specifying
canCreatePermissions
from outside?)aws-cdk/packages/@aws-cdk/aws-lambda/lib/function-base.ts
Lines 211 to 215 in 2640d9a
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: