Skip to content

Commit 29039e8

Browse files
author
Niranjan Jayakar
authoredNov 29, 2021
chore(apigatewayv2): integration api re-organization (#17752)
There are three major changes. `HttpRouteIntegration` (and its sibling `WebSocketRouteIntegration`) creates a CDK construct (`HttpIntegration` and `WebSocketIntegration`) as part of its bind operation. The id to this CDK construct is determined by hashing the results of the bind. Using hashes makes the construct id fragile/sensitive, consequently the CFN resource's logical id fragile. The fragility comes mainly from the question - have we hashed all of the expected properties that should be hashed, and nothing extra? If we have not hashed properties that should be there, or hashed too much, we end up with a hash change, hence resource replacement that is unexpected. This commit changes this approach and asks the user to provide the construct's id. This is more aligned with the current CDK expectation that users provide an id when initializing constructs. We just don't have a good way to validate that our hashing is accurate, so let's not do it at all. This change makes the user provide a unique name within a scope, which is already a standard requirement for CDK constructs. Secondly, the ergonomics of specific integration implementations, such as, `LambdaProxyIntegration`, `HttpAlbIntegration`, etc. is modified so that the integrating primitive is moved out of the 'props', and to the constructor. The API ergonomics of this feels much better than having to always provide a 'props'. Since this package contains constructs around both http api and websocket api, the convention to follow is that all classes specific to the former will be prefixed with `Http` and the latter will be prefixed with `WebSocket`. Bring the integration classes `LambdaProxyIntegration` and `HttpProxyIntegration` in line with this convention. These are renamed to `HttpLambdaIntegration` and `HttpUrlIntegration` respectively. BREAKING CHANGE: The `HttpIntegration` and `WebSocketIntegration` classes require an "id" parameter to be provided during its initialization. * **apigatewayv2-integrations:** The `LambdaWebSocketIntegration` is now renamed to `WebSocketLambdaIntegration`. The new class accepts the handler to the target lambda function directly in its constructor. * **apigatewayv2-integrations:** `HttpProxyIntegration` and `HttpProxyIntegrationProps` are now renamed to `HttpUrlIntegration` and `HttpUrlIntegrationProps` respectively. The new class accepts the target url directly in its constructor. * **apigatewayv2-integrations:** `LambdaProxyIntegration` and `LambdaProxyIntegrationProps` are now renamed to `HttpLambdaIntegration` and `HttpLambdaIntegrationProps` respectively. The new class accepts the lambda function handler directly in its constructor. * **apigatewayv2-integrations:** `HttpAlbIntegration` now accepts the ELB listener directly in its constructor. * **apigatewayv2-integrations:** `HttpNlbIntegration` now accepts the ELB listener directly in its constructor. * **apigatewayv2-integrations:** `HttpServiceDiscoveryIntegration` now accepts the service discovery Service directly in its constructor. * **apigatewayv2-authorizers:** `UserPoolAuthorizerProps` is now renamed to `HttpUserPoolAuthorizerProps`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a1685c6 commit 29039e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+281
-355
lines changed
 

‎packages/@aws-cdk/aws-apigatewayv2-authorizers/README.md

+11-25
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The example below showcases default authorization, along with route authorizatio
7171

7272
```ts
7373
import { HttpJwtAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
74-
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
74+
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
7575

7676
const authorizer = new HttpJwtAuthorizer({
7777
jwtAudience: ['3131231'],
@@ -84,34 +84,26 @@ const api = new apigwv2.HttpApi(this, 'HttpApi', {
8484
});
8585

8686
api.addRoutes({
87-
integration: new HttpProxyIntegration({
88-
url: 'https://get-books-proxy.myproxy.internal',
89-
}),
87+
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
9088
path: '/books',
9189
methods: [apigwv2.HttpMethod.GET],
9290
});
9391

9492
api.addRoutes({
95-
integration: new HttpProxyIntegration({
96-
url: 'https://get-books-proxy.myproxy.internal',
97-
}),
93+
integration: new HttpUrlIntegration('BooksIdIntegration', 'https://get-books-proxy.myproxy.internal'),
9894
path: '/books/{id}',
9995
methods: [apigwv2.HttpMethod.GET],
10096
});
10197

10298
api.addRoutes({
103-
integration: new HttpProxyIntegration({
104-
url: 'https://get-books-proxy.myproxy.internal',
105-
}),
99+
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
106100
path: '/books',
107101
methods: [apigwv2.HttpMethod.POST],
108102
authorizationScopes: ['write:books']
109103
});
110104

111105
api.addRoutes({
112-
integration: new HttpProxyIntegration({
113-
url: 'https://get-books-proxy.myproxy.internal',
114-
}),
106+
integration: new HttpUrlIntegration('LoginIntegration', 'https://get-books-proxy.myproxy.internal'),
115107
path: '/login',
116108
methods: [apigwv2.HttpMethod.POST],
117109
authorizer: new apigwv2.HttpNoneAuthorizer(),
@@ -136,7 +128,7 @@ Clients that fail authorization are presented with either 2 responses:
136128

137129
```ts
138130
import { HttpJwtAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
139-
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
131+
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
140132

141133
const authorizer = new HttpJwtAuthorizer({
142134
jwtAudience: ['3131231'],
@@ -146,9 +138,7 @@ const authorizer = new HttpJwtAuthorizer({
146138
const api = new apigwv2.HttpApi(this, 'HttpApi');
147139

148140
api.addRoutes({
149-
integration: new HttpProxyIntegration({
150-
url: 'https://get-books-proxy.myproxy.internal',
151-
}),
141+
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
152142
path: '/books',
153143
authorizer,
154144
});
@@ -165,7 +155,7 @@ pools as authorizer](https://docs.aws.amazon.com/apigateway/latest/developerguid
165155
```ts
166156
import * as cognito from '@aws-cdk/aws-cognito';
167157
import { HttpUserPoolAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
168-
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
158+
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
169159

170160
const userPool = new cognito.UserPool(this, 'UserPool');
171161
const userPoolClient = userPool.addClient('UserPoolClient');
@@ -178,9 +168,7 @@ const authorizer = new HttpUserPoolAuthorizer({
178168
const api = new apigwv2.HttpApi(this, 'HttpApi');
179169

180170
api.addRoutes({
181-
integration: new HttpProxyIntegration({
182-
url: 'https://get-books-proxy.myproxy.internal',
183-
}),
171+
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
184172
path: '/books',
185173
authorizer,
186174
});
@@ -195,7 +183,7 @@ Lambda authorizers depending on their response, fall into either two types - Sim
195183

196184
```ts
197185
import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '@aws-cdk/aws-apigatewayv2-authorizers';
198-
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
186+
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
199187

200188
// This function handles your auth logic
201189
declare const authHandler: lambda.Function;
@@ -209,9 +197,7 @@ const authorizer = new HttpLambdaAuthorizer({
209197
const api = new apigwv2.HttpApi(this, 'HttpApi');
210198

211199
api.addRoutes({
212-
integration: new HttpProxyIntegration({
213-
url: 'https://get-books-proxy.myproxy.internal',
214-
}),
200+
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
215201
path: '/books',
216202
authorizer,
217203
});

‎packages/@aws-cdk/aws-apigatewayv2-authorizers/lib/http/user-pool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { IUserPool, IUserPoolClient } from '@aws-cdk/aws-cognito';
33
import { Stack, Token } from '@aws-cdk/core';
44

55
/**
6-
* Properties to initialize UserPoolAuthorizer.
6+
* Properties to initialize HttpUserPoolAuthorizer.
77
*/
8-
export interface UserPoolAuthorizerProps {
8+
export interface HttpUserPoolAuthorizerProps {
99
/**
1010
* The user pool clients that should be used to authorize requests with the user pool.
1111
*/
@@ -43,7 +43,7 @@ export interface UserPoolAuthorizerProps {
4343
export class HttpUserPoolAuthorizer implements IHttpRouteAuthorizer {
4444
private authorizer?: HttpAuthorizer;
4545

46-
constructor(private readonly props: UserPoolAuthorizerProps) {
46+
constructor(private readonly props: HttpUserPoolAuthorizerProps) {
4747
}
4848

4949
public bind(options: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig {

0 commit comments

Comments
 (0)
Please sign in to comment.