3

I followed this tutorial to create a small chat application using python, aws apigategay and serverless. When connecting to the Websocket the connection ID is stored in a Database.

Everything works as expected, now I want to be able to connect to the Websocket with a role, lets say for example the chat allows customers and store employees.

I'm trying to find a way to send a parameter to the connect method but no luck so far. For example when establishing a connection I want to send a role ID and store in the database to specify that aconnection ID belongs to a customers or to store employees.

I read about the API gateway authorization but the thing is that the chat will be included in an application that's already running that is not using AWS authorization.

Is there any way to accomplish this?

1
  • Maybe something like queryStringParameters? but can't find any examples Commented May 5, 2020 at 14:22

2 Answers 2

9

You can send parameters via query string as follow:

 $  wscat -c wss://ws.mycustomdomain.com/?test=123

Then you can get that param from event.queryStringParameters in the function handler.

def handler(event, context):
    connectionId = event['queryStringParameters']['test']

Hope that helps 🍻

Sign up to request clarification or add additional context in comments.

Comments

1

Send the value as header in your connect call and retrieve it in backend to store alongside connectionId.

wscat --connect wss://aaaaaaaa.execute-api.us-east-2.amazonaws.com/test --header myHeader:myValue

In my lambda, the headers looked like,

"headers": {
        "Host": "xxxxxxx.execute-api.us-east-2.amazonaws.com",
        "myHeader": "myValue",
        "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
        "Sec-WebSocket-Key": "xxxxxxx",
        "Sec-WebSocket-Version": "13",
        "X-Amzn-Trace-Id": "xxxxxxx",
        "X-Forwarded-For": "xxxxxx",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.