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(apigatewayv2): cyclic dependency between HttpApi and the lambda function #9100

Merged
merged 4 commits into from
Aug 6, 2020

Conversation

nija-at
Copy link
Contributor

@nija-at nija-at commented Jul 16, 2020

As part of Lambda proxy integration, a AWS::Lambda::Permission
resource is created to provide the HTTP service permission to invoke
the lambda function, creating the dependency, Permission → API.
The API, on the other hand, needs to refer to the Function's ARN and
hence creates the dependency, API → Function.

However, when the lambda function and the HTTP API are placed in
different stacks, this creates a cyclic dependency between these two
stacks.

A picture is worth a thousand words:

 +--------------------------------------------------------------+
 | Lambda stack                                                 |
 |                                                              |
 |    +-------------------+            +-----------------+      |
 |    |                   | via ARN    |                 |      |
 |    | Lambda Permission +----------->| Lambda Function |      |
 |    |                   |            |                 |      |
 |    +-------+-----------+            +-----------------+      |
 |            |                                ^                |
 +------------|--------------------------------|----------------+
              |via ARN                         |via ARN
              |                                |
 +------------|--------------------------------|-----------------+
 |            v                                |                 |
 |      +-----------+               +----------+---------+       |
 |      |           |    via ID     |                    |       |
 |      |  Http API |<--------------+  API Integration   |       |
 |      |           |               |                    |       |
 |      +-----------+               +--------------------+       |
 |                                                               |
 | API Gateway stack                                             |
 +---------------------------------------------------------------+

The fix here is to move the Lambda Permission resource into the same
stack as where the API integration is defined, thereby breaking the
dependency cycle.
Now the 'API Gateway stack' will depend one way on the 'Lambda
stack'.

fixes #9075

BREAKING CHANGE: The parameter for the method bind() on
IHttpRouteIntegration has changed to accept one of type
HttpRouteIntegrationBindOptions. The previous parameter
IHttpRoute is now a property inside the new parameter under
the key route.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@nija-at nija-at requested a review from a team July 16, 2020 11:35
@nija-at nija-at self-assigned this Jul 16, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 16, 2020
…unction

As part of Lambda proxy integration, a `AWS::Lambda::Permission`
resource is created to provide the HTTP service permission to invoke
the lambda function, creating the dependency, Permission → API.
The API, on the other hand, needs to refer to the Function's ARN and
hence creates the dependency, API → Function.

However, when the lambda function and the HTTP API are placed in
different stacks, this creates a cyclic dependency between these two
stacks.

A picture is worth a thousand words:

```
 +--------------------------------------------------------------+
 | Lambda stack                                                 |
 |                                                              |
 |    +-------------------+            +-----------------+      |
 |    |                   | via ARN    |                 |      |
 |    | Lambda Permission +----------->| Lambda Function |      |
 |    |                   |            |                 |      |
 |    +-------+-----------+            +-----------------+      |
 |            |                                ^                |
 +------------|--------------------------------|----------------+
              |via ARN                         |via ARN
              |                                |
 +------------|--------------------------------|-----------------+
 |            v                                |                 |
 |      +-----------+               +----------+---------+       |
 |      |           |    via ID     |                    |       |
 |      |  Http API |<--------------+  API Integration   |       |
 |      |           |               |                    |       |
 |      +-----------+               +--------------------+       |
 |                                                               |
 | API Gateway stack                                             |
 +---------------------------------------------------------------+
```

The fix here is to move the Lambda Permission resource into the same
stack as where the API integration is defined.

fixes #9075

BREAKING CHANGE: The parameter for the method `bind()` on
`IHttpRouteIntegration` has changed to accept one of type
`HttpRouteIntegrationBindOptions`. The previous parameter
`IHttpRoute` is now a property inside the new parameter under
the key `route`.
@nija-at nija-at force-pushed the nija-at/apigwv2-cyclic-deps branch from 62b8e21 to a238c8d Compare July 16, 2020 11:39
@njlynch njlynch added the pr/do-not-merge This PR should not be merged at this time. label Jul 24, 2020
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

One docstring to fix. Otherwise looks good.

packages/@aws-cdk/aws-apigatewayv2/lib/http/integration.ts Outdated Show resolved Hide resolved
@nija-at nija-at removed the pr/do-not-merge This PR should not be merged at this time. label Aug 3, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 6, 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).

@mergify
Copy link
Contributor

mergify bot commented Aug 6, 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).

@mergify mergify bot merged commit 7b29774 into master Aug 6, 2020
@mergify mergify bot deleted the nija-at/apigwv2-cyclic-deps branch August 6, 2020 14:16
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

eladb pushed a commit that referenced this pull request Aug 10, 2020
…unction (#9100)

As part of Lambda proxy integration, a `AWS::Lambda::Permission`
resource is created to provide the HTTP service permission to invoke
the lambda function, creating the dependency, Permission → API.
The API, on the other hand, needs to refer to the Function's ARN and
hence creates the dependency, API → Function.

However, when the lambda function and the HTTP API are placed in
different stacks, this creates a cyclic dependency between these two
stacks.

A picture is worth a thousand words:

```
 +--------------------------------------------------------------+
 | Lambda stack                                                 |
 |                                                              |
 |    +-------------------+            +-----------------+      |
 |    |                   | via ARN    |                 |      |
 |    | Lambda Permission +----------->| Lambda Function |      |
 |    |                   |            |                 |      |
 |    +-------+-----------+            +-----------------+      |
 |            |                                ^                |
 +------------|--------------------------------|----------------+
              |via ARN                         |via ARN
              |                                |
 +------------|--------------------------------|-----------------+
 |            v                                |                 |
 |      +-----------+               +----------+---------+       |
 |      |           |    via ID     |                    |       |
 |      |  Http API |<--------------+  API Integration   |       |
 |      |           |               |                    |       |
 |      +-----------+               +--------------------+       |
 |                                                               |
 | API Gateway stack                                             |
 +---------------------------------------------------------------+
```

The fix here is to move the Lambda Permission resource into the same
stack as where the API integration is defined, thereby breaking the
dependency cycle. 
Now the 'API Gateway stack' will depend one way on the 'Lambda
stack'.

fixes #9075

BREAKING CHANGE: The parameter for the method `bind()` on
`IHttpRouteIntegration` has changed to accept one of type
`HttpRouteIntegrationBindOptions`. The previous parameter
`IHttpRoute` is now a property inside the new parameter under
the key `route`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

[apigatewayv2, lambda] Cyclic dependency between Lambda and HttpGateway
3 participants