Skip to content

feat(events): add WebSocketConnectionContext helper for APIGatewayV2WebSocketEvent (#273)#606

Open
ramanathan1504 wants to merge 2 commits into
aws:mainfrom
ramanathan1504:issue-273-websocket-session-context
Open

feat(events): add WebSocketConnectionContext helper for APIGatewayV2WebSocketEvent (#273)#606
ramanathan1504 wants to merge 2 commits into
aws:mainfrom
ramanathan1504:issue-273-websocket-session-context

Conversation

@ramanathan1504
Copy link
Copy Markdown

This change addresses #273 by adding a session-like, Lambda-safe connection context for API Gateway WebSocket events.

What changed

  • Added WebSocketConnectionContext to APIGatewayV2WebSocketEvent in aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEvent.java
  • Added convenience accessors:
    • APIGatewayV2WebSocketEvent#getConnectionContext()
    • APIGatewayV2WebSocketEvent.RequestContext#getConnectionContext()
  • Added getManagementApiEndpoint() to build https://{domainName}/{stage} for API Gateway Management API usage
  • Added null/empty fallback behavior for endpoint parts (domainName, stage)
  • Added tests in aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2WebSocketEventTest.java
  • Documented usage and null-safe handling in aws-lambda-java-events/README.md
  • Added release note entry in aws-lambda-java-events/RELEASE.CHANGELOG.md

Why

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

  • Non-breaking: existing event fields and getters remain unchanged.
  • Existing code using requestContext.getConnectionId() continues to work.
  • New behavior is additive only.

Error handling / fallback

  • getConnectionContext() returns null when requestContext or connectionId is missing.
  • getManagementApiEndpoint() returns null when domainName or stage is missing/empty.
  • No new exceptions introduced.

@ramanathan1504 ramanathan1504 force-pushed the issue-273-websocket-session-context branch from c03ff0e to 85691d9 Compare May 13, 2026 18:01
@ramanathan1504 ramanathan1504 force-pushed the issue-273-websocket-session-context branch from 85691d9 to c163bfa Compare May 13, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant