【问题标题】:Commands in .ebextensions fails on ElasticBeanstalk.ebextensions 中的命令在 ElasticBeanstalk 上失败
【发布时间】:2023-03-22 18:00:02
【问题描述】:

我正在尝试使用 AWS CodePipeline 将我的 Node.js 应用程序部署到 AWS ElasticBeanstalk。由于我的应用程序使用 WebSockets,因此我在 .ebextensions 中包含了以下配置文件。

container_commands:
  enable_websocket:
    command: 
      sed -i '/\s*proxy_set_header\s*Connection/c \
              proxy_set_header Upgrade $http_upgrade;\
              proxy_set_header Connection "upgrade";\
          ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf

但是,CodePipeline 在部署过程中失败,并且 ElasticBeanstalk 日志文件 cfn-init.log 显示如下:

2020-06-18 12:43:42,345 [INFO] -----------------------Starting build-----------------------
2020-06-18 12:43:42,352 [INFO] Running configSets: Infra-EmbeddedPostBuild
2020-06-18 12:43:42,355 [INFO] Running configSet Infra-EmbeddedPostBuild
2020-06-18 12:43:42,359 [INFO] Running config postbuild_0_drcha
2020-06-18 12:43:42,381 [ERROR] Command enable_websockets (sed -i '/\s*proxy_set_header\s*Connection/c \
        proxy_set_header Upgrade $http_upgrade;\
        proxy_set_header Connection "upgrade";\
        ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf) failed
2020-06-18 12:43:42,381 [ERROR] Error encountered during build of postbuild_0_drcha: Command enable_websockets failed
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command enable_websockets failed
2020-06-18 12:43:42,383 [ERROR] -----------------------BUILD FAILED!------------------------
2020-06-18 12:43:42,383 [ERROR] Unhandled exception during build: Command enable_websockets failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 171, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 129, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 530, in build
    self.run_config(config, worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command enable_websockets failed

失败的原因是什么?

【问题讨论】:

    标签: amazon-web-services nginx amazon-elastic-beanstalk


    【解决方案1】:

    我不确定为什么会发生错误,但如果您使用的是 Amazon Linux 2 平台(于 2020 年 4 月 30 日针对 Node.js 推出),那么您可以更轻松地自定义 nginx 配置。

    Extending Elastic Beanstalk Linux platforms 中所述,您可以在.platform/nginx/nginx.conf 放置一个自定义的nginx 文件,部署将自动使用它。您可能需要检查默认配置并以此为基础。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,并且遇到了同样的配置,但也不起作用。经过进一步的调查,我找到了正确的配置(至少到目前为止)。

      files:
        "/etc/nginx/conf.d/websockets.conf":
          content: |
      
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
      
      

      我发布了a blog article,如果您在其他配置方面需要帮助,这可能会有所帮助。

      【讨论】:

      • 这救了我。我从Node.js running on 64bit Amazon Linux 移动到64bit Amazon Linux 2 v5.2.4 running Node.js 12 后遇到了这个问题。我正在使用旧方法通过 websockets 设置 nginx。感谢您分享您的解决方案。
      【解决方案3】:

      这里的秘密是来自container_commands 的完整日志和回溯位于/var/log/cfn-init-cmd.log(在 2020 年 11 月发布的 Amazon Linux 2 Elastic Beanstalk 上)。要阅读此内容,您将运行:

      eb ssh [environment-name]
      sudo tail -n 50 -f /var/log/cfn-init-cmd.log
      

      这似乎没有在任何明显的地方记录下来,并且在您运行eb logs 时也不会显示。我是在/var/log四处寻找才发现的。

      对于希望运行 Django 管理命令的读者,请参阅Running Django migrations when deploying to Elastic Beanstalk

      【讨论】:

        猜你喜欢
        • 2020-11-02
        • 2014-03-08
        • 2015-03-22
        • 2014-07-09
        • 2017-05-24
        • 2013-12-20
        • 2016-06-30
        • 2015-09-27
        • 2019-06-17
        相关资源
        最近更新 更多