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): trigger on websocket connect and disconnect is not working #27732

Merged
merged 22 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36fadef
create integ test from ryan sample code, without assertions yet though
sumupitchayan Oct 24, 2023
4cc1116
add lambdas folder
sumupitchayan Oct 24, 2023
b0bf397
rename typo integ test file
sumupitchayan Oct 24, 2023
51fae38
cleanup integ test case
sumupitchayan Oct 24, 2023
d04233d
add integ assertion, although it is not working yet - need to figure …
sumupitchayan Oct 24, 2023
a6eb9dc
temporarily make assertion 'getRoutes'
sumupitchayan Oct 25, 2023
35a43f0
remove /* from lambda permission resource name
sumupitchayan Oct 27, 2023
480ad72
remove integ assertion, cannot find a way to test this
sumupitchayan Oct 27, 2023
091b9c9
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
sumupitchayan Oct 27, 2023
cedb1a8
update integ snapshots
sumupitchayan Oct 30, 2023
841cd68
Merge branch 'sumughan/apigwv2-addroutes-integration-not-working' of …
sumupitchayan Oct 30, 2023
6931b86
update apigw snapshots
sumupitchayan Oct 30, 2023
11460b3
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
sumupitchayan Oct 30, 2023
34a29eb
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
sumupitchayan Oct 30, 2023
ed0691d
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
sumupitchayan Oct 31, 2023
bdc692b
use integ test construct
sumupitchayan Oct 31, 2023
5769e24
update snapshots again, trying to get build to succeed
sumupitchayan Oct 31, 2023
23ce211
update snapshots AGAIN
sumupitchayan Oct 31, 2023
273e2e0
update integ.lambda snapshots in websocket
sumupitchayan Oct 31, 2023
83a6e16
update snapshots in authorizers websocket/integ.iam test
sumupitchayan Oct 31, 2023
0b759c9
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
sumupitchayan Oct 31, 2023
2c7614a
Merge branch 'main' into sumughan/apigwv2-addroutes-integration-not-w…
mergify[bot] Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class WebSocketLambdaIntegration extends WebSocketRouteIntegration {
sourceArn: Stack.of(route).formatArn({
service: 'execute-api',
resource: route.webSocketApi.apiId,
resourceName: `*/*${route.routeKey}`,
resourceName: `*${route.routeKey}`,
}),
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { WebSocketApi, WebSocketStage } from '@aws-cdk/aws-apigatewayv2-alpha';
import * as cdk from 'aws-cdk-lib';
import { WebSocketLambdaIntegration } from '../../lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as path from 'path';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

const app = new cdk.App();

const stack = new cdk.Stack(app, 'integ-apigwv2-lambda-connect-integration');
const webSocketTableName = 'WebSocketConnections';

const connectFunction = new lambda.Function(stack, 'Connect Function', {
functionName: 'process_connect_requests',
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambdas', 'connect')),
timeout: cdk.Duration.seconds(5),
environment: {
TABLE_NAME: webSocketTableName,
},
});

const disconnectFunction = new lambda.Function(
stack,
'Disconnect Function',
{
functionName: 'process_disconnect_requests',
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(
path.join(__dirname, 'lambdas', 'disconnect'),
),
timeout: cdk.Duration.seconds(5),
environment: {
TABLE_NAME: webSocketTableName,
},
},
);

const webSocketLogTable = new dynamodb.Table(stack, 'WebSocket Log Table', {
tableName: webSocketTableName,
partitionKey: {
name: 'ConnectionId',
type: dynamodb.AttributeType.STRING,
},
removalPolicy: cdk.RemovalPolicy.DESTROY, // not recommended for production
});
webSocketLogTable.grantReadWriteData(connectFunction);
webSocketLogTable.grantReadWriteData(disconnectFunction);

const webSocketConnectIntegration = new WebSocketLambdaIntegration(
'ConnectIntegration',
connectFunction,
);
const webSocketDisconnectIntegration = new WebSocketLambdaIntegration(
'DisconnectIntegration',
disconnectFunction,
);

const webSocketApi = new WebSocketApi(stack, 'WebSocket API', {
apiName: 'webSocket',
routeSelectionExpression: '$request.body.action',
connectRouteOptions: { integration: webSocketConnectIntegration },
disconnectRouteOptions: { integration: webSocketDisconnectIntegration },
});

new WebSocketStage(
stack,
'Production Stage',
{
webSocketApi: webSocketApi,
stageName: 'prod',
autoDeploy: true,
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "connect",
"version": "1.0.0",
"description": "connect example for WebSockets on API Gateway",
"main": "index.js",
"author": "SAM CLI",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.690.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "disconnect",
"version": "1.0.0",
"description": "disconnect example for WebSockets on API Gateway",
"main": "index.js",
"author": "SAM CLI",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.690.0"
}
}
Loading