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

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

Closed
musketyr opened this issue Jan 15, 2019 · 4 comments
Closed

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

musketyr opened this issue Jan 15, 2019 · 4 comments
Assignees

Comments

@musketyr
Copy link

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
}
@PatrykGala
Copy link

PatrykGala commented Feb 26, 2019

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");
    }
}

lucasam pushed a commit to lucasam/aws-lambda-java-libs that referenced this issue Jul 28, 2019
 * extendedRequestId
 * requestTime
 * requestTimeEpoch
 * domainName
 * protocol
 * connectionId
 * routeKey
 * messageId
 * eventType
 * messageDirection
 * connectedAt
 Fixes issues
 aws#88
 aws#76
 aws#71
 aws#41
@lucasam
Copy link

lucasam commented Aug 1, 2019

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

@carlzogh
Copy link
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

@musketyr
Copy link
Author

thanks, that looks correct!

maxday added a commit that referenced this issue Oct 22, 2024
* example app

* now with annotation serialization

* Add moshi serializer

* Add jackson-jr serializer

* Add fastJson serializer

* Add gson serializer

* Add RequestStreamHandler(GSON) example

* feat: document BYOS

* feat: document BYOS

* feat: document BYOS

* feat: document BYOS

* fix: lint

* fix: bump to java21

* fix: add samples in GitHub actions

* fix: GitHub Actions

* fix: GitHub Actions

* fix: remove gradlew

* fix: bump versions

* fix: test GitHub action failure

* fix: simplify Jackson Sample

* fix: bump dependencies, remove junit, cleanup templates

* fix: remove junit

* fix: use try with resources

---------

Co-authored-by: Mark Sailes <[email protected]>
Co-authored-by: Andrea Culot <[email protected]>
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

No branches or pull requests

5 participants