Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

APIGW Websocket $connect message fails to parse #71

Closed
alistaim opened this issue Feb 22, 2022 · 1 comment
Closed

APIGW Websocket $connect message fails to parse #71

alistaim opened this issue Feb 22, 2022 · 1 comment

Comments

@alistaim
Copy link

When a lambda function is attached to the $CONNECT route in a Websocket API, I get parsing errors e.g.

Error: Error("data did not match any variant of untagged enum LambdaRequest", line: 0, column: 0)

The raw request looks like this :

{
    "headers": {
        "Host": "blah.execute-api.us-west-2.amazonaws.com",
        "Sec-WebSocket-Key": "Q2062s5dM2uhnYdgQyQ8kg==",
        "Sec-WebSocket-Version": "13",
        "X-Amzn-Trace-Id": "Root=1-62153479-78192ed94f7a987b6cdbfc41",
        "x-api-key": "theapikey",
        "X-Forwarded-For": "0.0.0.0",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "multiValueHeaders": {
        "Host": [
            "blah.execute-api.us-west-2.amazonaws.com"
        ],
        "Sec-WebSocket-Key": [
            "Q2062s5dM2uhnYdgQyQ8kg=="
        ],
        "Sec-WebSocket-Version": [
            "13"
        ],
        "X-Amzn-Trace-Id": [
            "Root=1-62153479-78192ed94f7a987b6cdbfc41"
        ],
        "x-api-key": [
            "theapikey"
        ],
        "X-Forwarded-For": [
            "0.0.0.0"
        ],
        "X-Forwarded-Port": [
            "443"
        ],
        "X-Forwarded-Proto": [
            "https"
        ]
    },
    "requestContext": {
        "routeKey": "$connect",
        "eventType": "CONNECT",
        "extendedRequestId": "N9UjFHPGvHcF99g=",
        "requestTime": "22/Feb/2022:19:07:37 +0000",
        "messageDirection": "IN",
        "stage": "dev",
        "connectedAt": 1645556857902,
        "requestTimeEpoch": 1645556857902,
        "identity": {
            "apiKey": "theapikey",
            "apiKeyId": "blah",
            "sourceIp": "0.0.0.0"
        },
        "requestId": "N9UjFHPGvHcF99g=",
        "domainName": "blah.execute-api.us-west-2.amazonaws.com",
        "connectionId": "N9UjFc6FPHcCIOw=",
        "apiId": "blah"
    },
    "isBase64Encoded": false
}

The lambda handler code is very simple :

use lambda_http::{service_fn, Error, IntoResponse, Request, RequestExt};
use tracing::{debug, info};

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::TRACE)
        .with_ansi(false)
        .without_time()
        .init();

    lambda_http::run(service_fn(func)).await?;
    Ok(())
}

async fn func(event: Request) -> Result<impl IntoResponse, Error> {
    debug!("Raw event : {:?}", event);
    info!("Received request ID : {}", event.lambda_context().request_id);
    Ok(format!("Hello world !").into_response())
}

The code above parses the fixture file correctly.

@calavera
Copy link
Owner

Fixed by #72

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants