0

I have been following this article - https://blog.mangoforbreakfast.com/2017/02/13/django-channels-on-aws-elastic-beanstalk-using-an-alb/

to get my django-channels app working on aws..but only non-websockets request are getting handled.

my channel layer setting is :

   CHANNEL_LAYERS = {
"default": {
    "BACKEND": "asgi_redis.RedisChannelLayer",
    "CONFIG": {
        "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
    },
    "ROUTING": "malang.routing.channel_routing",
 },
}

I have two target group as mentioned in the article. One forwarding path / to port 80 and /ws/* to 5000.

My supervisord.conf is -

[program:Daphne]
environment=PATH="/opt/python/run/venv/bin"
command=/opt/python/run/venv/bin/daphne -b 0.0.0.0 -p 5000 
malang.asgi:channel_layer
directory=/opt/python/current/app
autostart=true
autorestart=true
redirect_stderr=true
user=root
stdout_logfile=/tmp/daphne.out.log

[program:Worker]
environment=PATH="/opt/python/run/venv/bin"
command= /opt/python/run/venv/bin/python manage.py runworker
directory=/opt/python/current/app
process_name=%(program_name)s_%(process_num)02d
numprocs=4
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/workers.out.log

When I check the result of supervisorctl status on aws logs it shows them running fine. But still I get 404 response for ws.

Please help and let me know if you want some more info..

Pradeep Saini
  • 306
  • 1
  • 3
  • 13

2 Answers2

0

Does the project run locally? If not, the issue is with the software. If so, the issue is with your deployment. I would check the security group/firewall/ELB configuration to ensure the correct ports are accessible.

  • it runs perfectly fine locally. One question..should the redis port `"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],` be same as the port of daphne ? because as of now I am running daphne on 5000 and redis is defined to run on 6379. – Pradeep Saini Jun 25 '17 at 18:27
  • @PradeepSaini I don't know anything about daphne, so I can't tell you how to configure it. – Clinton Blackburn Jun 26 '17 at 18:58
0

It makes no sense to run a Redis backend locally on each instance, provided the fact that you actually deployed it, which you don't given your info. Redis is a cache system that allow data sharing through different instances. Closer to a DB on architectural point of view that a simple daemon thread. You should use a external Redis Cache instead and refer to it on you Django conf.

CHANNEL_LAYERS = {
"default": {
    "BACKEND": "asgi_redis.RedisChannelLayer",
    "ROUTING": "<YOUR_APP>.routing.application",
    "CONFIG": {
        "hosts": ["redis://"+REDIS_URL+":6379"],
    },
},

}

See AWS ElasticCache service for that.

MaxBlax360
  • 1,070
  • 1
  • 12
  • 15