Search code examples
node.jsamazon-web-servicesnginxamazon-elastic-beanstalkamazon-linux-2

Error deploying a node.js app to Elastic Beanstalk on Amazon Linux 2


I am trying to have a node js app on Elastic Beanstalk. On Amazon Linux Image the environment gets created and works smooth.In order to get it done I followed the instructions given in the AWS documentation itself. It works on single instance.Also,using Nginx and have terminated HTTPS on the instance by following the info here The root directory of the app contains:

  • .ebextensions
  • index.js
  • package.json

By following all those instructions step by step given in AWS documentation the environment is created and the app is deployed successfully(For Amazon Linux Image).

However, been trying to deploy it to Amazon Linux 2.And the deployment fails with the Health status for the environment being "DEGRADED".

A snippet of the eb-engine.log:

[INFO] 
> [email protected] install /var/app/staging/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

Failed to execute '/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/bin/node /opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --library=static_library --module=/var/app/staging/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node --module_name=grpc_node --module_path=/var/app/staging/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)

Snippet of the web.stdout.log:

Sep 13 12:55:31 ip-172-31-1-73 web: > [email protected] start /var/app/current
Sep 13 12:55:31 ip-172-31-1-73 web: > node index.js
Sep 13 12:55:31 ip-172-31-1-73 web: [DEFAULT]
Sep 13 12:55:32 ip-172-31-1-73 web: events.js:174
Sep 13 12:55:32 ip-172-31-1-73 web: throw er; // Unhandled 'error' event
Sep 13 12:55:32 ip-172-31-1-73 web: ^
Sep 13 12:55:32 ip-172-31-1-73 web: Error: listen EACCES: permission denied 0.0.0.0:80
Sep 13 12:55:32 ip-172-31-1-73 web: at Server.setupListenHandle [as _listen2] (net.js:1260:19)

Snippet from nginx/error.log:

 2020/09/13 13:06:31 [alert] 4023#0: *1021 1024 worker_connections are not enough while connecting to upstream, client: 127.0.0.1, server: , request: "GET /hudson HTTP/1.1", upstream: "http://127.0.0.1:80/hudson", host: "*SOME IP ADDRESS*"

For deploying the app on Amazon Linux 2 Elastic beanstalk the root folder of the app consists of the following files/folders:

  • .ebextensions/https-instance.config and .ebextensions/https-instance-single.config
  • .platform/nginx/conf.d/extendnginx.conf (In order to extend the nginx config so as to terminate the https at the instance)
  • index.js
  • package.json

The instance type is a Single instance, t2.micro.


Solution

  • You cannot run your application on port 80 and 443 because these ports are exclusive for Nginx/Apache service inside Beanstalk AMI. Instead of using these ports, use 8080 for HTTP connections and 8443 to HTTPS connections.