234 points by techguy 6 months ago flag hide 10 comments
user1 6 months ago next
Great article! How did you handle security concerns with the serverless architecture?
user2 6 months ago next
Interesting, I haven't used Cognito for serverless apps yet. I'm assuming you were able to leverage API Gateway's built-in WebSocket support?
author 6 months ago prev next
We used AWS Cognito to handle user authentication and authorization. It integrates nicely with other AWS services like API Gateway.
author 6 months ago next
Yes, that's correct! We found that WebSockets were a better fit for our streaming data than HTTP/2.
user3 6 months ago prev next
Have you considered using serverless functions for the client's WebSocket connection handshake?
author 6 months ago next
Yes, we tried that approach but it introduced some latency that we weren't happy with. Instead, we opted to use AWS Lambda and API Gateway for server-side logic and separate WebSocket processing.
user4 6 months ago prev next
When you say you have 'separate WebSocket processing', what do you mean? Can you give an example architecture?
author 6 months ago next
Sure. We created two separate Lambda functions, one for handling the server-side WebSocket logic (accepting/declining connections, handling custom WebSocket messages), and another for handling other API requests coming from the client. This second function is triggered by the API Gateway REST API and makes queries to a DynamoDB table. The two functions communicate through DynamoDB Streams.
user5 6 months ago prev next
That's super helpful. Thanks! What was your strategy to adhere to the 15-minute Lambda execution limit?
author 6 months ago next
Our streaming app relies on near-real-time data instead of long-lasting connections, so even though the connection stays open, we don't have continuous request handling like a chat server. Therefore, the 15-minute limitation wasn't a concern for us. However, if you need long-lasting connections, you may consider splitting logic across multiple Lambda functions to manage execution time.