aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.61k stars 1.01k forks source link

Support Sending Websocket API Messages from all handlers #1357

Open subssn21 opened 4 years ago

subssn21 commented 4 years ago

I am working with the experimental Websockets API, and so far it is working great.

The one issue I did run into was that I want to send a message to my websocket from for instance my SQS Queue when it was done processing an item on the queue.

Now keeping track of the connection ID is clearly the application developers job, however access the send api was a problem.

websocket_api.configure is not called except for websocket handlers.

I was able to work around it by setting the api URL in an environment variable and checking to see if _endpoint_url has been set and set it if not.

Everything work after that.

So the request is to call configure on websocket_api for all handlers regardless of being websocket or not (or make it easy to do in app.py)

There may. be a better way already and I am just not aware of it.

Thanks,

Mike

jamesls commented 4 years ago

Seems like a reasonable use case. It might be challenging to implement. We're calling configure with parameters we get from the event object passed in to our web socket handler. In order to call configure from all handlers, we'd have to get the domain name and stage from somewhere else besides the event object. Maybe we can record it somewhere at deploy time.

Any thoughts @stealthycoin?

subssn21 commented 3 years ago

It looks like it is already stored in /chalice/deployed/{env}.json

In the websocket_api section.

Can that be read by Chalice inside the Lambda?

dkosilov commented 3 years ago

Are there any updates on the issue?

BeattieM commented 1 year ago

Yeah I'm trying to do the same thing by combining sockets and SNS events. Basically having devices connect to the socket and get messages over the socket from a lambda that is invoked via an SNS event.