Skip to content

fix(event-targets): circular dependency when the lambda target is in a different stack#11217

Merged
mergify[bot] merged 5 commits intomasterfrom
nija-at/lambda-event-cyclic
Oct 30, 2020
Merged

fix(event-targets): circular dependency when the lambda target is in a different stack#11217
mergify[bot] merged 5 commits intomasterfrom
nija-at/lambda-event-cyclic

Conversation

@nija-at
Copy link
Copy Markdown
Contributor

@nija-at nija-at commented Oct 30, 2020

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

…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
@nija-at nija-at requested a review from a team October 30, 2020 10:27
@nija-at nija-at self-assigned this Oct 30, 2020
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Oct 30, 2020

expect(stack).toCountResources('AWS::Lambda::Permission', 1);
});

test('lambda handler and cloudwatch event across stacks', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a test for an imported Rule, as that changes the behavior?

Copy link
Copy Markdown
Contributor Author

@nija-at nija-at Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this any different for imported Rule? Imported Rules also follow the same logic.

Copy link
Copy Markdown
Contributor

@njlynch njlynch Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind. I thought the if (rule instanceof Construct) { was a check against imported rules. But I see that's not the case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imported resources are also a Construct. They inherit Resource which is a subclass of Construct.

The if statement is needed because IRule and Construct don't overlap. But so far there is no case when the Rule will not be a Construct.

@nija-at nija-at requested a review from njlynch October 30, 2020 11:16
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 30, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 3f9586b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Oct 30, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lambda] Cannot avoid circular dependency when lambda and cloudwatch-events resources are in different stacks

3 participants