forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apigatewayv2): multiple http integrations are created for each ro…
…ute (aws#12528) Currently when we define any HTTP integration (like ALB, NLB etc.) explicitly and use it for multiple routes, the `HttpRoute` construct will create a new `HttpIntegration` resource for each of these routes. [Ref](https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-apigatewayv2/lib/http/route.ts#L128) These extra HttpIntegration (and hence `CfnIntegration`) are not required since the same integration can be used for all the routes. This feature is supported in console as well (i.e. selecting same integration for multiple routes). A sample snippet: ```ts const apiGateway = new apigw.HttpApi(this, apiLableApiGateway); const apiIntegration = new apigwint.HttpAlbIntegration({ listener : apiListener, vpcLink : apiVpcLink }); const apiRoutes = [ { method: apigw.HttpMethod.ANY, path: '/' }, { method: apigw.HttpMethod.GET, path: '/status' }, { method: apigw.HttpMethod.GET, path: '/whateverelse' }, ]; for (const apiRouteIndex in apiRoutes) { const apiRouteMethod = apiRoutes[apiRouteIndex].method; const apiRoutePath = apiRoutes[apiRouteIndex].path; apiGateway.addRoutes({ methods : [apiRouteMethod], path : apiRoutePath, integration : apiIntegration, }); } ``` The root cause of this issue is that the current api resource does not keep track of any existing integrations with the same integration config. We are solving this issue by keeping track of these integrations in an internal map with key as stringified value of `HttpRouteIntegrationConfig` (which we get by calling the `bind` function) and value as the `HttpIntegration`. This ensures that we reuse any existing integration (with same config) instead of creating a new one for every route. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
e74f61b
commit d873d51
Showing
8 changed files
with
213 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.