Skip to content

WebSocket support #402

Closed
Closed
@ymwjbxxq

Description

@ymwjbxxq

Hello,

I think the request API Gateway WebSocket API to AWS Lambda is not supported.

So if you are using Request from lambda_http

You have this error

Error: Error("data did not match any variant of untagged enum LambdaRequest",

and so to make it work, it is possible only to use lambda_runtime and create your structure

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Event {
    pub request_context: RequestContext,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RequestContext {
    pub event_type: EventType,
    pub connection_id: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "UPPERCASE")]
pub enum EventType {
    Connect,
    Disconnect,
}

It would be nice to access the complete request out of the box.

{
   "headers":"Object("{
      "Host":"String(""xxxx.execute-api.xxxx.amazonaws.com"")",
      "Sec-WebSocket-Extensions":"String(""permessage-deflate; client_max_window_bits"")",
      "Sec-WebSocket-Key":"String(""xxxx"")",
      "Sec-WebSocket-Version":"String(""13"")",
      "X-Amzn-Trace-Id":"String(""Root=1-61e2cb5d-xxxx"")",
      "X-Forwarded-For":"String(""xxx.xxx.xxx.xxx"")",
      "X-Forwarded-Port":"String(""443"")",
      "X-Forwarded-Proto":"String(""https"")"
   }")",
   "isBase64Encoded":"Bool(false)",
   "multiValueHeaders":"Object("{
      "Host":"Array("[
         "String(""xxxx.execute-api.xxxx.amazonaws.com"")"
      ]")",
      "Sec-WebSocket-Extensions":"Array("[
         "String(""permessage-deflate; client_max_window_bits"")"
      ]")",
      "Sec-WebSocket-Key":"Array("[
         "String(""xxxx"")"
      ]")",
      "Sec-WebSocket-Version":"Array("[
         "String(""13"")"
      ]")",
      "X-Amzn-Trace-Id":"Array("[
         "String(""Root=1-61e2cb5d-xxxx"")"
      ]")",
      "X-Forwarded-For":"Array("[
         "String(""xxx.xxx.xxx.xxx"")"
      ]")",
      "X-Forwarded-Port":"Array("[
         "String(""443"")"
      ]")",
      "X-Forwarded-Proto":"Array("[
         "String(""https"")"
      ]")"
   }")",
   "requestContext":"Object("{
      "apiId":"String(""xxxxxx"")",
      "connectedAt":Number(1642253149666),
      "connectionId":"String(""L_S2qf_VliACH_g="")",
      "domainName":"String(""xxxx.execute-api.xxxx.amazonaws.com"")",
      "eventType":"String(""CONNECT"")",
      "extendedRequestId":"String(""L_S2qHEVFiAFk9w="")",
      "identity":"Object("{
         "sourceIp":"String(""xxx.xxx.xxx.xxx"")"
      }")",
      "messageDirection":"String(""IN"")",
      "requestId":"String(""L_S2qHEVFiAFk9w="")",
      "requestTime":"String(""15/Jan/2022:13:25:49 +0000"")",
      "requestTimeEpoch":Number(1642253149666),
      "routeKey":"String(""$connect"")",
      "stage":"String(""test"")"
   }")"
}

Thanks

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