Skip to content

Commit e2da141

Browse files
authored
Merge branch 'master' into master
2 parents 216950d + 22b9b3d commit e2da141

Some content is hidden

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

60 files changed

+2357
-537
lines changed

.github/workflows/pr-linter.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
# https://github.com/actions/toolkit/blob/master/packages/github/src/context.ts
33

44
name: PR Linter
5-
on: pull_request
5+
on:
6+
pull_request:
7+
types:
8+
- labeled
9+
- unlabeled
10+
- edited
11+
- opened
12+
- synchronize
13+
- reopened
614

715
jobs:
816
validate-pr:

packages/@aws-cdk/assets/lib/fs/options.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export interface CopyOptions {
1010
* A strategy for how to handle symlinks.
1111
*
1212
* @default Never
13-
* @deprecated use `followSymlinks` instead
1413
*/
1514
readonly follow?: FollowMode;
1615

packages/@aws-cdk/aws-apigatewayv2-integrations/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
- [Lambda Integration](#lambda)
2222
- [HTTP Proxy Integration](#http-proxy)
2323
- [Private Integration](#private-integration)
24+
- [WebSocket APIs](#websocket-apis)
25+
- [Lambda WebSocket Integration](#lambda-websocket-integration)
2426

2527
## HTTP APIs
2628

@@ -146,3 +148,32 @@ const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
146148
}),
147149
});
148150
```
151+
152+
## WebSocket APIs
153+
154+
WebSocket integrations connect a route to backend resources. The following integrations are supported in the CDK.
155+
156+
### Lambda WebSocket Integration
157+
158+
Lambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects
159+
or sends message specific to a route, the API Gateway service forwards the request to the Lambda function
160+
161+
The API Gateway service will invoke the lambda function with an event payload of a specific format.
162+
163+
The following code configures a `sendmessage` route with a Lambda integration
164+
165+
```ts
166+
const webSocketApi = new WebSocketApi(stack, 'mywsapi');
167+
new WebSocketStage(stack, 'mystage', {
168+
webSocketApi,
169+
stageName: 'dev',
170+
autoDeploy: true,
171+
});
172+
173+
const messageHandler = new lambda.Function(stack, 'MessageHandler', {...});
174+
webSocketApi.addRoute('sendmessage', {
175+
integration: new LambdaWebSocketIntegration({
176+
handler: connectHandler,
177+
}),
178+
});
179+
```

packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/lambda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class LambdaProxyIntegration implements IHttpRouteIntegration {
4141
principal: new ServicePrincipal('apigateway.amazonaws.com'),
4242
sourceArn: Stack.of(route).formatArn({
4343
service: 'execute-api',
44-
resource: route.httpApi.httpApiId,
44+
resource: route.httpApi.apiId,
4545
resourceName: `*/*${route.path ?? ''}`, // empty string in the case of the catch-all route $default
4646
}),
4747
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './http';
2+
export * from './websocket';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lambda';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
IWebSocketRouteIntegration,
3+
WebSocketIntegrationType,
4+
WebSocketRouteIntegrationBindOptions,
5+
WebSocketRouteIntegrationConfig,
6+
} from '@aws-cdk/aws-apigatewayv2';
7+
import { ServicePrincipal } from '@aws-cdk/aws-iam';
8+
import { IFunction } from '@aws-cdk/aws-lambda';
9+
import { Names, Stack } from '@aws-cdk/core';
10+
11+
/**
12+
* Lambda WebSocket Integration props
13+
*/
14+
export interface LambdaWebSocketIntegrationProps {
15+
/**
16+
* The handler for this integration.
17+
*/
18+
readonly handler: IFunction
19+
}
20+
21+
/**
22+
* Lambda WebSocket Integration
23+
*/
24+
export class LambdaWebSocketIntegration implements IWebSocketRouteIntegration {
25+
constructor(private props: LambdaWebSocketIntegrationProps) {}
26+
27+
bind(options: WebSocketRouteIntegrationBindOptions): WebSocketRouteIntegrationConfig {
28+
const route = options.route;
29+
this.props.handler.addPermission(`${Names.nodeUniqueId(route.node)}-Permission`, {
30+
scope: options.scope,
31+
principal: new ServicePrincipal('apigateway.amazonaws.com'),
32+
sourceArn: Stack.of(route).formatArn({
33+
service: 'execute-api',
34+
resource: route.webSocketApi.apiId,
35+
resourceName: `*/*${route.routeKey}`,
36+
}),
37+
});
38+
39+
return {
40+
type: WebSocketIntegrationType.AWS_PROXY,
41+
uri: this.props.handler.functionArn,
42+
};
43+
}
44+
}

0 commit comments

Comments
 (0)