Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets on Elastic Beanstalk with Docker

Trying to deploy a Docker image in AWS Elastic Beanstalk running on a single instance for now. It all works fine, apart from WebSockets which I am using through Socket.IO.

Another post suggests to remove nginx, but that is either not possible anymore or just not an option for deployments with Docker.

I have a python script that changes the nginx configuration to allow WebSocket connections. When I ssh into the instance and run that script, it works. However, that part of the nginx configuration does not exist yet when ebextensions are run, so I cannot run this script automatically.

If you want to try it yourself, I am trying to deploy databench_examples. It is working when you deploy this with eb init and eb start and then ssh into the instance and go to /var/app/current and run sudo python nginx_socketio_conf.py which changes the nginx configuration file. If it is not working, you see a 500 error in the browser console for the Socket.IO handshake when running the simplepi analysis.

like image 980
svenkreiss Avatar asked Jul 17 '14 19:07

svenkreiss


People also ask

Does Elastic Beanstalk support Docker?

Elastic Beanstalk supports the deployment of web applications from Docker containers. With Docker containers, you can define your own runtime environment.

Is AWS Elastic Beanstalk a container service?

Elastic Beanstalk is an AWS service for deploying and scaling web applications and services. It eliminates the need to manually launch AWS resources required to run applications. Using your IDE, AWS Management Console, or Git repository, you upload the Docker container image.


1 Answers

You're correct that the nginx configuration file does not exist when ebextensions are run. Here's why: that config file is dynamically generated after the application is deployed because the port mapping for the Docker container isn't known until after the container stops. So your awesome Python script executed by ebextensions doesn't have a config file to operate on.

Another conventional approach doesn't work, i.e., writing the nginx config file to /etc/nginx/conf.d because the location directive has to exist inside the server block in the sites_enabled config. So that's a no go.

I created a PR to illustrate an approach that will work: https://github.com/svenkreiss/databench_examples/pull/3 This is an undocumented technique that drops the Python/nginx mutation script into the right place in Elastic Beanstalk's hooks directory. The script is then executed by Elastic Beanstalk immediately after the nginx configuration is generated (Elastic Beanstalk will run executable scripts in the hooks subdirectories in alphabetical order, hence the 01_ prefix.

Thanks,

Evan

like image 93
Evan Brown Avatar answered Sep 29 '22 00:09

Evan Brown