Skip to content

Add Support for API Gateway Proxy events for WebSocket API #71

Closed

Description

@musketyr

the event for API Gateway Proxy events for WebSocket API has different format of the requestContext. Please, add support for these events as well.

{
    "requestContext": {
        "routeKey": "$default",
        "messageId": "Ti89OAAt3vcAAAQ=",
        "eventType": "MESSAGE",
        "extendedRequestId": "Ti89OF32joEFbiA=",
        "requestTime": "15/Jan/2019:13:09:27 +0000",
        "messageDirection": "IN",
        "stage": "test",
        "connectedAt": 1547557733712,
        "requestTimeEpoch": 1547557767850,
        "identity": {
            "sourceIp": "89.24.55.85"
        },
        "requestId": "Ti89OF32joEFbiA=",
        "domainName": "jzla12ar9e.execute-api.eu-west-1.amazonaws.com",
        "connectionId": "Ti835f_GEowCETQ=",
        "apiId": "jzla12ar9e"
    },
    "body": "hello",
    "isBase64Encoded": false
}

Activity

  1. PatrykGala commented on Feb 26, 2019

    @PatrykGala

    Workaround:

    public class ConnectHandler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
        private static final Logger LOG = LogManager.getLogger(ConnectHandler.class);
    
        @Override
        public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
            String connectionId = extractConnectionId(input);
            LOG.info("connectionid: {}", connectionId);
            return ApiGatewayResponse.ok(connectionId);
        }
    
        private String extractConnectionId(Map<String, Object> input) {
            Map<String, Object> requestContext = (Map<String, Object>) input.get("requestContext");
            return (String) requestContext.get("connectionId");
        }
    }
    
  2. lucasam commented on Aug 1, 2019

    @lucasam

    I believe this PR #92 fixes this issue.
    A new class https://github.com/aws/aws-lambda-java-libs/blob/master/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyRequestEvent.java is created to handle APIGatewayV2 parameters

    Still not present at version 2.6.0. Needs to be built from sources

  3. carlzogh commented on Apr 29, 2020

    @carlzogh
    Contributor

    Hey @musketyr - support for API Gateway WebSocket API events was released in version 2.2.7 of the aws-lambda-java-events library as APIGatewayV2ProxyRequest and APIGatewayV2ProxyResponse events.
    The RequestContext model you're looking for is defined here https://github.com/aws/aws-lambda-java-libs/blob/master/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2ProxyRequestEvent.java#L215-L554

  4. musketyr commented on Apr 30, 2020

    @musketyr
    Author

    thanks, that looks correct!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions