Deploying Django Channels to AWS ECS

Hi - I’m working on an application which is already deployed via AWS’ Elastic Container Service (ECS). We have a Celery worker and a Gunicorn web server running.

We’d like to add websockets to the application, have it working locally, and I’m now trying to figure out the best way to deploy it. I’ve read this gist about setting things up with Elastic Beanstalk, however that won’t be a 1 for 1 mapping with ECS. In particular, if we create a 2nd target group for the Daphne server and use a load balancer to route traffic at /ws to it, I’m not sure how we’d handle health checks for that target group (AWS target groups require an http endpoint which returns a 200).

I’m also considering switching all traffic to being served by Daphne rather than splitting it up between Gunicorn for wsgi and Daphne for asgi however I’m a little cautious about that based on other forum posts about splitting that up. Perhaps Daphne is more mature now and this isn’t as much of a concern?

Has anyone setup websockets with Gunicorn and Daphne on AWS ECS? Or, would anyone advise to completely switch over to Daphne (or Uvicorn) for all traffic?

Welcome @nburt !

If I had that kind of situation, I’d set up a singular “status” endpoint that could handle that type of health check.

My decisions in that area aren’t based on Daphne’s “immaturity”, they’re more philosophical, and still hold for all the same reasons as I mentioned in that thread you have referenced.

I won’t say that you shouldn’t try it, it’s just not a decision that I would make.

Thanks!

Gotcha. I suppose I was more referencing Carlton’s response in that thread on the unknowns. I hear you on the philosophical side. My background is primarily in Ruby / Rails where there aren’t different ASGI / WSGI servers and Puma can handle all kinds of requests so it’s really something I haven’t ever considered.

I’ll see if I can make things work with a 2nd target group and if not will just switch over fully to Daphne or Uvicorn.

I’ve served plenty of project ASGI only with Daphne. It’s fine. My point is that the scaling patterns for WSGI are better known (completely known). I suspect this is a premature optimisation in a lot of cases.

1 Like