feat(events): add WebSocketConnectionContext helper for APIGatewayV2WebSocketEvent (#273)#606
Conversation
85691d9 to
c163bfa
Compare
… APIGatewayV2WebSocketEvent
8cc24e7 to
e2f1a0d
Compare
|
Hello @ramanathan1504, thanks for your contribution, any help is appreciated ❤️ Before diving into implementation details, I'd love to understand the use case better and make sure we're solving the right problem. Every class in Issue #273 asks for a Were you thinking about Lambda Managed Instances and their multi-concurrency model as a use case here? Besides that, the example provided in the README looks to me functionally identical to the one using using WebSocketConnectionContext WebSocketConnectionContext connection = event.getConnectionContext();
if (connection != null) {
String connectionId = connection.getConnectionId();
String endpoint = connection.getManagementApiEndpoint();
}using RequestContext var rc = event.getRequestContext();
if (rc != null && rc.getConnectionId() != null) {
String connectionId = rc.getConnectionId();
String endpoint = "https://" + rc.getDomainName() + "/" + rc.getStage();
}The only saving is the URL concatenation. Could you share a scenario where this meaningfully reduces the complexity for the end user? Thanks again for your time! |
This change addresses #273 by adding a session-like, Lambda-safe connection context for API Gateway WebSocket events.
What changed
WebSocketConnectionContexttoAPIGatewayV2WebSocketEventinaws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEvent.javaAPIGatewayV2WebSocketEvent#getConnectionContext()APIGatewayV2WebSocketEvent.RequestContext#getConnectionContext()getManagementApiEndpoint()to buildhttps://{domainName}/{stage}for API Gateway Management API usagedomainName,stage)aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEventTest.javaaws-lambda-java-events/README.mdaws-lambda-java-events/RELEASE.CHANGELOG.mdWhy
AWS Lambda WebSocket events do not provide a native Java
WebSocketSession. This helper provides a lightweight session-like object built from event metadata (connectionId,domainName,stage) so handlers can easily pass one context object through their business logic.Backward compatibility
requestContext.getConnectionId()continues to work.Error handling / fallback
getConnectionContext()returnsnullwhenrequestContextorconnectionIdis missing.getManagementApiEndpoint()returnsnullwhendomainNameorstageis missing/empty.