Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commands in .ebextensions fails on ElasticBeanstalk

I'm trying to deploy my Node.js application to AWS ElasticBeanstalk with AWS CodePipeline. Since my application is using WebSockets, I included the following config file in .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

However, the CodePipeline fails on the deployment process and the ElasticBeanstalk log file cfn-init.log says follows:

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

What is the reason for the failure?

like image 575
김승수 Avatar asked Oct 18 '25 09:10

김승수


2 Answers

The secret here is that the full logs and tracebacks from container_commands are in /var/log/cfn-init-cmd.log (on Amazon Linux 2 Elastic Beanstalk released November 2020). To read this you would run:

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

This doesn't seem to be documented anywhere obvious and it's not displayed when you run eb logs. I only found it by hunting around in /var/log.

For readers looking to run Django management commands, see Running Django migrations when deploying to Elastic Beanstalk

like image 52
Ben Sturmfels Avatar answered Oct 21 '25 02:10

Ben Sturmfels


I had this exact same issue and came across the same configuration that also didn't work. After further sleuthing, I found the correct configuration (at least as of now).

files:
  "/etc/nginx/conf.d/websockets.conf":
    content: |

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

I posted a blog article that might be helpful if you need help on additional configuration.

like image 26
Darshan Somashekar Avatar answered Oct 21 '25 02:10

Darshan Somashekar