-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): integration class does not render an integration resource #17729
Conversation
…esource Routes on APIGateway V2 can integrate with different backends. This is achieved by creating the CFN resource `AWS::ApiGatewayV2::Integration` that is then referenced in the resource for the Route. Currently, the `IHttpRouteIntegration` (and `IWebSocketRouteIntegration`) interface represents a unique backend that a route can integrate with, using the CDK "bind" pattern. An integration can be bound to any number of routes but should be rendered into a single instance of `AWS::ApiGatewayV2::Integration` resource. To achieve this currently, the `HttpApi` (and `WebSocketApi`) class holds a cache of all integrations defined against its routes. This is the wrong level of caching and causes a number of problems. 1. We rely on the configuration of the `AWS::ApiGateway::Integration` resource to determine if one already exists. This means that two instances of `IHttpRouteIntegration` can result in rendering only one instance of `AWS::ApiGateway::Integration` resource. Users may want to intentionally generate multiple instances of `AWS::ApiGateway::Integration` classes with the same configuration. Taking away this power with CDK "magic" is just confusing. 2. Currently, we allow using the same instance of `IHttpRouteIntegration` (or `IWebSocketRouteIntegration`) to be bound to routes in different `HttpApi`. When bound to the route, the CDK renders an instance of `AWS::ApiGatewayV2::Integration` for each API. This is another "magic" that has the potential for user confusion and bugs. The solution is to KeepItSimple™. Remove the API level caching and simply cache at the level of each integration. This ensures that each instance of `HttpRouteIntegration` (previously `IHttpRouteIntegration`) renders to exactly one instance of `AWS::ApiGatewayV2::Integration`. Disallow using the same instance of `HttpRouteIntegration` across different instances of `HttpApi`. fixes #13213 BREAKING CHANGE: The interface `IHttpRouteIntegration` is replaced by the abstract class `HttpRouteIntegration`. * **apigatewayv2:** The interface `IWebSocketRouteIntegration` is now replaced by the abstract class `WebSocketRouteIntegration`. * **apigatewayv2:** Previously, we allowed the usage of integration classes to be used with routes defined in multiple `HttpApi` instances (or `WebSocketApi` instances). This is now disallowed, and separate instances must be created for each instance of `HttpApi` or `WebSocketApi`.
}); | ||
|
||
function hash(x: any) { | ||
const stringifiedConfig = JSON.stringify(Stack.of(options.scope).resolve(x)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it can happen with Stack
s (maybe resolve()
already takes care of that), but if the order of the fields change or if the presence or absence of whitespaces change, the hash will be different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace is not a problem here. Ordering maybe. I'll check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ordering is actually a bigger problem here than I thought.
This PR is effectively not changing the logic of hashing. Just moving it to a different place (previously integration-cache.ts
).
Do you mind if I take this on as a follow up PR? Easier to review as well.
I have a different solution in mind that effectively removes the need to hash.
@nija-at If I am remember correctly, this was an explicit request from customers. I think this is something that the API Gateway console allows to do. That is, a single integration can be bound to multiple APIs and is typically created out of the scope of an API. Do you think this change might create a problem with that and/or customer might ask for it again? |
I don't know how that is possible since the |
Yeah that's true. Maybe I am remembering something else. The change LGTM! |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…esource (aws#17729) Routes on APIGateway V2 can integrate with different backends. This is achieved by creating the CFN resource `AWS::ApiGatewayV2::Integration` that is then referenced in the resource for the Route. Currently, the `IHttpRouteIntegration` (and `IWebSocketRouteIntegration`) interface represents a unique backend that a route can integrate with, using the CDK "bind" pattern. An integration can be bound to any number of routes but should be rendered into a single instance of `AWS::ApiGatewayV2::Integration` resource. To achieve this currently, the `HttpApi` (and `WebSocketApi`) class holds a cache of all integrations defined against its routes. This is the wrong level of caching and causes a number of problems. 1. We rely on the configuration of the `AWS::ApiGateway::Integration` resource to determine if one already exists. This means that two instances of `IHttpRouteIntegration` can result in rendering only one instance of `AWS::ApiGateway::Integration` resource. Users may want to intentionally generate multiple instances of `AWS::ApiGateway::Integration` classes with the same configuration. Taking away this power with CDK "magic" is just confusing. 2. Currently, we allow using the same instance of `IHttpRouteIntegration` (or `IWebSocketRouteIntegration`) to be bound to routes in different `HttpApi`. When bound to the route, the CDK renders an instance of `AWS::ApiGatewayV2::Integration` for each API. This is another "magic" that has the potential for user confusion and bugs. The solution is to KeepItSimple™. Remove the API level caching and simply cache at the level of each integration. This ensures that each instance of `HttpRouteIntegration` (previously `IHttpRouteIntegration`) renders to exactly one instance of `AWS::ApiGatewayV2::Integration`. Disallow using the same instance of `HttpRouteIntegration` across different instances of `HttpApi`. fixes aws#13213 BREAKING CHANGE: The interface `IHttpRouteIntegration` is replaced by the abstract class `HttpRouteIntegration`. * **apigatewayv2:** The interface `IWebSocketRouteIntegration` is now replaced by the abstract class `WebSocketRouteIntegration`. * **apigatewayv2:** Previously, we allowed the usage of integration classes to be used with routes defined in multiple `HttpApi` instances (or `WebSocketApi` instances). This is now disallowed, and separate instances must be created for each instance of `HttpApi` or `WebSocketApi`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…esource (aws#17729) Routes on APIGateway V2 can integrate with different backends. This is achieved by creating the CFN resource `AWS::ApiGatewayV2::Integration` that is then referenced in the resource for the Route. Currently, the `IHttpRouteIntegration` (and `IWebSocketRouteIntegration`) interface represents a unique backend that a route can integrate with, using the CDK "bind" pattern. An integration can be bound to any number of routes but should be rendered into a single instance of `AWS::ApiGatewayV2::Integration` resource. To achieve this currently, the `HttpApi` (and `WebSocketApi`) class holds a cache of all integrations defined against its routes. This is the wrong level of caching and causes a number of problems. 1. We rely on the configuration of the `AWS::ApiGateway::Integration` resource to determine if one already exists. This means that two instances of `IHttpRouteIntegration` can result in rendering only one instance of `AWS::ApiGateway::Integration` resource. Users may want to intentionally generate multiple instances of `AWS::ApiGateway::Integration` classes with the same configuration. Taking away this power with CDK "magic" is just confusing. 2. Currently, we allow using the same instance of `IHttpRouteIntegration` (or `IWebSocketRouteIntegration`) to be bound to routes in different `HttpApi`. When bound to the route, the CDK renders an instance of `AWS::ApiGatewayV2::Integration` for each API. This is another "magic" that has the potential for user confusion and bugs. The solution is to KeepItSimple™. Remove the API level caching and simply cache at the level of each integration. This ensures that each instance of `HttpRouteIntegration` (previously `IHttpRouteIntegration`) renders to exactly one instance of `AWS::ApiGatewayV2::Integration`. Disallow using the same instance of `HttpRouteIntegration` across different instances of `HttpApi`. fixes aws#13213 BREAKING CHANGE: The interface `IHttpRouteIntegration` is replaced by the abstract class `HttpRouteIntegration`. * **apigatewayv2:** The interface `IWebSocketRouteIntegration` is now replaced by the abstract class `WebSocketRouteIntegration`. * **apigatewayv2:** Previously, we allowed the usage of integration classes to be used with routes defined in multiple `HttpApi` instances (or `WebSocketApi` instances). This is now disallowed, and separate instances must be created for each instance of `HttpApi` or `WebSocketApi`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
…esource (aws#17729) Routes on APIGateway V2 can integrate with different backends. This is achieved by creating the CFN resource `AWS::ApiGatewayV2::Integration` that is then referenced in the resource for the Route. Currently, the `IHttpRouteIntegration` (and `IWebSocketRouteIntegration`) interface represents a unique backend that a route can integrate with, using the CDK "bind" pattern. An integration can be bound to any number of routes but should be rendered into a single instance of `AWS::ApiGatewayV2::Integration` resource. To achieve this currently, the `HttpApi` (and `WebSocketApi`) class holds a cache of all integrations defined against its routes. This is the wrong level of caching and causes a number of problems. 1. We rely on the configuration of the `AWS::ApiGateway::Integration` resource to determine if one already exists. This means that two instances of `IHttpRouteIntegration` can result in rendering only one instance of `AWS::ApiGateway::Integration` resource. Users may want to intentionally generate multiple instances of `AWS::ApiGateway::Integration` classes with the same configuration. Taking away this power with CDK "magic" is just confusing. 2. Currently, we allow using the same instance of `IHttpRouteIntegration` (or `IWebSocketRouteIntegration`) to be bound to routes in different `HttpApi`. When bound to the route, the CDK renders an instance of `AWS::ApiGatewayV2::Integration` for each API. This is another "magic" that has the potential for user confusion and bugs. The solution is to KeepItSimple™. Remove the API level caching and simply cache at the level of each integration. This ensures that each instance of `HttpRouteIntegration` (previously `IHttpRouteIntegration`) renders to exactly one instance of `AWS::ApiGatewayV2::Integration`. Disallow using the same instance of `HttpRouteIntegration` across different instances of `HttpApi`. fixes aws#13213 BREAKING CHANGE: The interface `IHttpRouteIntegration` is replaced by the abstract class `HttpRouteIntegration`. * **apigatewayv2:** The interface `IWebSocketRouteIntegration` is now replaced by the abstract class `WebSocketRouteIntegration`. * **apigatewayv2:** Previously, we allowed the usage of integration classes to be used with routes defined in multiple `HttpApi` instances (or `WebSocketApi` instances). This is now disallowed, and separate instances must be created for each instance of `HttpApi` or `WebSocketApi`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Routes on APIGateway V2 can integrate with different backends. This is
achieved by creating the CFN resource
AWS::ApiGatewayV2::Integration
that is then referenced in the resource for the Route.
Currently, the
IHttpRouteIntegration
(andIWebSocketRouteIntegration
)interface represents a unique backend that a route can integrate with,
using the CDK "bind" pattern.
An integration can be bound to any number of routes but should be
rendered into a single instance of
AWS::ApiGatewayV2::Integration
resource.
To achieve this currently, the
HttpApi
(andWebSocketApi
) classholds a cache of all integrations defined against its routes.
This is the wrong level of caching and causes a number of problems.
We rely on the configuration of the
AWS::ApiGateway::Integration
resource to determine if one already exists.
This means that two instances of
IHttpRouteIntegration
can resultin rendering only one instance of
AWS::ApiGateway::Integration
resource.
Users may want to intentionally generate multiple instances of
AWS::ApiGateway::Integration
classes with the same configuration.Taking away this power with CDK "magic" is just confusing.
Currently, we allow using the same instance of
IHttpRouteIntegration
(orIWebSocketRouteIntegration
) to be boundto routes in different
HttpApi
. When bound to the route, the CDKrenders an instance of
AWS::ApiGatewayV2::Integration
for each API.This is another "magic" that has the potential for user confusion and
bugs.
The solution is to KeepItSimple™.
Remove the API level caching and simply cache at the level of each
integration. This ensures that each instance of
HttpRouteIntegration
(previously
IHttpRouteIntegration
) renders to exactly one instance ofAWS::ApiGatewayV2::Integration
.Disallow using the same instance of
HttpRouteIntegration
acrossdifferent instances of
HttpApi
.fixes #13213
BREAKING CHANGE: The interface
IHttpRouteIntegration
is replaced bythe abstract class
HttpRouteIntegration
.IWebSocketRouteIntegration
is nowreplaced by the abstract class
WebSocketRouteIntegration
.classes to be used with routes defined in multiple
HttpApi
instances(or
WebSocketApi
instances). This is now disallowed, and separateinstances must be created for each instance of
HttpApi
orWebSocketApi
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license