I'm running a global service where customers connect through WebSockets. Ideally, we have a 60-second keep-alive, which fits well since CloudFront's idle timeout is 10 minutes. However, I know some devices might not send this keep-alive and could idle for up to 10 minutes. We also evaluated Azure Front Door, which has a hard limit of 4 hours for connections. I'm curious if CloudFront has a similar restriction. I didn't find anything about this in the documentation, aside from the mentioned idle timeout. Has anyone here dealt with WebSockets in a similar application? Any insights or experiences would be really helpful!
5 Answers
You could also consider routing your WebSockets through CloudFront to API Gateway which upgrades the connection from HTTPS to WSS. As for the timeout, I've heard the idle limit is 10 minutes, with a max connection time of 2 hours.
It seems like there's a bit of confusion here. CloudFront isn't just for caching; it also offers DDoS protection, which could be useful for your setup.
If your WebSocket connection is actively being used, CloudFront won’t time it out. But if it goes idle, it will eventually disconnect after 10 minutes, and the client will need to reconnect, which honestly isn’t a bad thing.
Why not have the clients just reconnect if they detect a disconnect? I built a system where WebSockets communicated with an ALB. Disconnections weren't too frequent unless there were network issues, and our clients were programmed to reconnect automatically, which worked well for us.
AWS AppSync could be really beneficial for your setup if you're looking for something that handles WebSocket connections more smoothly.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads