amazon-web-services - Django channel 2 和 EC2/Elasticbeanstalk

标签 amazon-web-services amazon-ec2 websocket amazon-elastic-beanstalk django-channels

我的简短问题是,如何在 AWS Elasticbeanstalk 上设置 Django-channels v2?下面是冗长且不那么吸引人的问题。 提前致谢!


我正在尝试使用 Django Channels 2.02 设置一个 elasticbeanstalk 实例。我跟着这个https://hackernoon.com/setting-up-django-channels-on-aws-elastic-beanstalk-716fd5a49c4a教程。为 channel 1 制作的教程。

Elasticbeanstalk 实例是使用应用程序负载均衡器 创建的。 Redis 4.0 实例正在运行 0.0.0.0:6379,由 netstat 确认。自定义 TCP,端口范围:6379,来源:redis 实例上的 0.0.0.0/0。

.ebekstension 中的 alb_listener.config:

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

Daphne 服务器使用命令“Daphne .asgi:application”启动。监听 TCP 地址 0.0.0.0:8000。它返回:

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

Websocket 在浏览器控制台中没有返回错误。

它适用于我的本地运行服务器设置。问题是什么?你能帮我写一个配置脚本,这样我就不需要手动启动 Daphne 了吗?

最佳答案

这里的回复很晚。

问题出在教程中的 config:hosts URL 上。从 URL 中删除 redis:// 部分。

例如,

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

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

您可以使用 redis-cli 检查连接,

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

关于amazon-web-services - Django channel 2 和 EC2/Elasticbeanstalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49231599/

相关文章:

hadoop - 错误配置 : namenode address dfs. namenode.servicerpc-address 或 dfs.namenode.rpc-address 没有配置

postgresql - 在 ec2 实例上部署 Java EE webapp

grails - 使用 Grails 3 spring-websocket 访问 WebSocketConfigurer

amazon-web-services - 什么是 AWS 中的 vCPU

amazon-web-services - SES 电子邮件配额是否适用于 Amazon Cognito 发送的验证邮件?

amazon-web-services - CloudFormation 不断为我的 S3 存储桶模板的部署抛出 InvalidBucketAclWithBlockPublicAccessError

amazon-web-services - AWS 为负载均衡器请求 ACM HTTPS 证书

java - akka websocket with java,计算客户端数量,向客户端发送消息

java - WebSocket握手时出错: Unexpected response code: 404

amazon-web-services - 单个 Vagrantfile 可以同时拥有 AWS 和 VirtualBox 提供商吗?