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): HttpApi and Route in different stacks creates cycles #13010

Merged
merged 6 commits into from
Feb 15, 2021
Merged

fix(apigatewayv2): HttpApi and Route in different stacks creates cycles #13010

merged 6 commits into from
Feb 15, 2021

Conversation

hoegertn
Copy link
Contributor

@hoegertn hoegertn commented Feb 12, 2021

When the Route construct with an integration is defined
in a separate stack from the one defining the HttpApi
construct, a circular dependency error is thrown.

The bug was introduced in - 855ce59 - where the
refactor of moving the creation of Integration resulted in
using the HttpApi as the scope of the Integration
construct, rather than the Route.

fixes #13021


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

@gitpod-io
Copy link

gitpod-io bot commented Feb 12, 2021

@mergify
Copy link
Contributor

mergify bot commented Feb 12, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@hoegertn
Copy link
Contributor Author

@eladb @nija-at I modified the code to keep the old semantic of using the route scope for the integration.

But I see the benefit of the Integration being tied to the API scope.

I think ideally the integration should be scoped depending on the integration type and for Lambda integrations it should be in the same scope as the function, as this causes the cyclic dependency.

@nija-at
Copy link
Contributor

nija-at commented Feb 15, 2021

But I see the benefit of the Integration being tied to the API scope.

I'm curious what the benefit is?

I think ideally the integration should be scoped depending on the integration type and for Lambda integrations it should be in the same scope as the function, as this causes the cyclic dependency.

Do you mean when the lambda is in the API scope or just any other stack?

It feels reasonable to assume that the lambda function will be defined closer to the integration rather than the API.

@nija-at nija-at changed the title WIP: fix(api-gatewayv2): modify broken scope of HttpIntegration fix(apigatewayv2): HttpApi and Route in different stacks creates cycles Feb 15, 2021
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 label Feb 15, 2021
@hoegertn
Copy link
Contributor Author

But I see the benefit of the Integration being tied to the API scope.

I'm curious what the benefit is?

The set of integrations for deduplication is located at the API and integrations are possibly reused, so they should live at the top level.

I think ideally the integration should be scoped depending on the integration type and for Lambda integrations it should be in the same scope as the function, as this causes the cyclic dependency.

Do you mean when the lambda is in the API scope or just any other stack?

It feels reasonable to assume that the lambda function will be defined closer to the integration rather than the API.

The integration should live in the same stack as the Lambda function at any time. Just not sure about other integrations that are not Lambda.

But I am totally happy to have integrations located at the route as in my PR, I am just not sure as I never reused integrations and want to see if this breaks other peoples workflows.

@nija-at
Copy link
Contributor

nija-at commented Feb 15, 2021

The integration should live in the same stack as the Lambda function at any time.

It could also live in another stack, no?

How about taking scope as an optional parameter as part of integration's props and defaulting to the Route's scope if not provided?

@hoegertn
Copy link
Contributor Author

The integration should live in the same stack as the Lambda function at any time.

It could also live in another stack, no?

It references the Lambda function so it could only live in the same stack or downstream but not more to the top.

Api -> Lambda -> Integ

@nija-at
Copy link
Contributor

nija-at commented Feb 15, 2021

The integration should live in the same stack as the Lambda function at any time.

It could also live in another stack, no?

It references the Lambda function so it could only live in the same stack or downstream but not more to the top.

Api -> Lambda -> Integ

Agreed.

@ayush987goyal
Copy link
Contributor

@hoegertn Thanks for this change! I did not realise this flow while making the change.

I am just curious on why have you decided to make the scope as optional and defaulted to this in the _addIntegration helper? I think we should always make it scoped in the Route?

@nija-at
Copy link
Contributor

nija-at commented Feb 15, 2021

@hoegertn Thanks for this change! I did not realise this flow while making the change.

I am just curious on why have you decided to make the scope as optional and defaulted to this in the _addIntegration helper? I think we should always make it scoped in the Route?

Good point. And we should make scope the first argument on the method, just like in any Construct.

@hoegertn
Copy link
Contributor Author

@hoegertn Thanks for this change! I did not realise this flow while making the change.

I am just curious on why have you decided to make the scope as optional and defaulted to this in the _addIntegration helper? I think we should always make it scoped in the Route?

The _addIntegration could be called from another place outside of the scope of a route. So I thought a default of the API as the parent might be a good idea.

@ayush987goyal
Copy link
Contributor

The _addIntegration could be called from another place outside of the scope of a route. So I thought a default of the API as the parent might be a good idea.

I am just thinking if this problem would then occur in that context? Better we force the callers to pass the scope. Thoughts?

@nija-at
Copy link
Contributor

nija-at commented Feb 15, 2021

The _addIntegration could be called from another place outside of the scope of a route. So I thought a default of the API as the parent might be a good idea.

I am just thinking if this problem would then occur in that context? Better we force the callers to pass the scope. Thoughts?

Let's make scope mandatory and make it the first parameter of the method (to keep it consistent with our existing patterns). Better to be explicit than implicit. This is an internal API, so we can change it later when we learn more.

nija-at
nija-at previously approved these changes Feb 15, 2021
@mergify mergify bot dismissed nija-at’s stale review February 15, 2021 14:06

Pull request has been modified.

@nija-at nija-at added pr/do-not-merge This PR should not be merged at this time. and removed pr/do-not-merge This PR should not be merged at this time. labels Feb 15, 2021
@mergify
Copy link
Contributor

mergify bot commented Feb 15, 2021

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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 4028e0c
  • 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 Feb 15, 2021

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 b5efb88 into aws:master Feb 15, 2021
@hoegertn hoegertn deleted the hoegertn/api-gatewayv-regression-13007 branch February 15, 2021 15:13
NovakGu pushed a commit to NovakGu/aws-cdk that referenced this pull request Feb 18, 2021
…es (aws#13010)

When the Route construct with an integration is defined
in a separate stack from the one defining the HttpApi
construct, a circular dependency error is thrown.

The bug was introduced in - 855ce59 - where the
refactor of moving the creation of Integration resulted in
using the HttpApi as the scope of the Integration
construct, rather than the Route.

fixes aws#13021

----

*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
@aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apigatewayv2): cyclic dependency introduced when HttpApi and Route are in different stacks
4 participants