Skip to content
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

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

Merged
merged 5 commits into from
Oct 30, 2020

Conversation

nija-at
Copy link
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

gitpod-io bot commented Oct 30, 2020

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

test('lambda handler and cloudwatch event across stacks', () => {
Copy link
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
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
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
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
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
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
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