3
votes

My short question, how to setup Django-channels v2 on AWS Elasticbeanstalk? The long and less inviting questions underneath. Thank you in advance!


I am trying to set up an elasticbeanstalk instance using Django Channels 2.02. I followed this https://hackernoon.com/setting-up-django-channels-on-aws-elastic-beanstalk-716fd5a49c4a tutorial. Tutorial made for Channels 1.

The Elasticbeanstalk instance was created with an application load balancer. The Redis 4.0 instance is running 0.0.0.0:6379, confirmed by netstat. Custom TCP, Port Range: 6379, Source: 0.0.0.0/0 on redis instance.

alb_listener.config in .ebekstension:

option_settings:   aws:elbv2:listener:80:
    DefaultProcess: http
    ListenerEnabled: 'true'
    Protocol: HTTP   aws:elasticbeanstalk:environment:process:http:
    Port: '8000'
    Protocol: HTTP

Daphne server startet with command "Daphne .asgi:application". Listening on TCP address 0.0.0.0:8000. It returns:

2018-03-12 08:59:30,778 ERROR    Exception inside application: [Errno -2] Name or service not known
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
    await await_many_dispatch([receive, self.channel_receive], self.dispatch)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/utils.py", line 47, in await_many_dispatch
    result = task.result()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 167, in receive
    task.result()
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 187, in receive_loop
    real_channel, message = await self.receive_single(general_channel)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 224, in receive_single
    async with self.connection(index) as connection:
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 403, in __aenter__
    self.conn = await aioredis.create_redis(**self.kwargs)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 174, in create_redis
    loop=loop)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/connection.py", line 107, in create_connection
    timeout, loop=loop)
  File "/usr/lib64/python3.6/asyncio/tasks.py", line 339, in wait_for
    return (yield from fut)
  File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
    lambda: protocol, host, port, **kwds)
  File "/usr/lib64/python3.6/asyncio/base_events.py", line 733, in create_connection
    infos = f1.result()
  File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib64/python3.6/socket.py", line 743, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  [Errno -2] Name or service not known

The Websocket returns no error in browser console.

It works on my local runserver setup. What is the problem? Can you please help me write a config script so that I don't need to start Daphne manually?

1
Hey, Did you find a solution for this? I'm frequently getting this issue on EC2. Thanks - BoCode
Hello @BoCode , sorry but I did not find an answer. - Espen Finnesand
I'm trying the same thing! If you get success tell me plz - Karl Zillner
This is a mystery to me so far. Will inform you once i find a solution. - BoCode
Channels 2 doesnt use daphne...Im trying to get channels 2 working on elastic beanstalk too....but my error is different - Karl Zillner

1 Answers

0
votes

Very late reply here.

The problem is with config:hosts URL in the tutorial. Remove the redis:// portion from the URL.

For instance,

REDIS_PUBLIC_DNS = "YOUR-REDIS-DNS.amazonaws.com"

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [(REDIS_PUBLIC_DNS, 6379)],
        }
    }
}

You can check the connection using redis-cli,

redis-cli -h REDIS-PUBLIC-DNS-url ping ;you should expect PONG in response.