Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Turn WebSockets into Async/Await Requests (AWS WebSocket API Gateway + Lambda)

DEV Community·Rishi·30 days ago
#14bdLu5X
Reading 0:00
15s threshold

Some time ago, I was building a chat application using AWS Websocket API gateway. Things were going smoothly. I created a WebSocket API Gateway, added $connect, $disconnect, and sendMessage/addGroup routes. From the frontend (React) side, everything was fire-and-forget. You send a message, and the onMessageHandler takes care of it 💪🏼 But then a new requirement of uploading files using S3 signed URLs came up. That's where I needed the Async/Await promise pattern. Now, one option was to create an HTTP API gateway and use it. But that meant a new connection, a new authorizer, and more setup. At that moment, I wished there was a way to use this existing WebSocket connection to get the signed URL ⭐ And that’s how this library " ws-await " was born! It lets you: establish a WebSocket connection send normal fire-and-forget messages send messages and wait for the response using async/await handle reconnection with exponential backoff auto-send heartbeat messages to keep the connection alive How does it work?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More