Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

I had a similar issue with NodeJS (express) and Application Load Balancer (AWS). The issue was in the keep-alive timeout configuration, the NodeJS application default timeout was set to a shorter period than the timeout configured on the load balancer which resulted in the server dropping the connection in the middle of a request (made from the load balancer).

A simple fix was setting the server.keepAliveTimeout to a higher number than configured on the load balancer.

The default keep alive for nginx is 75 sec; The default keep alive for NodeJS is 5 sec.


In Elastic Beanstalk, you can set the keepAliveTimeout for your Node.js server by modifying the server's configuration through a .ebextensions configuration file. This allows you to customize various settings of your environment, including your Node.js server settings.

Here's how you can set the keepAliveTimeout for your Node.js server in Elastic Beanstalk:

  1. Create a .ebextensions directory in the root of your application (if it doesn't already exist).

  2. Inside the .ebextensions directory, create a file with a .config extension. For example, nodejs-keep-alive-timeout.config.

  3. Open the .config file in a text editor and add the following content:

Code Block
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/enact/05_set_keepalive_timeout.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      echo "keepAliveTimeout: 75000" >> /tmp/deployment.config

container_commands:
  01_copy_config:
    command: "cp -f /tmp/deployment.config /etc/httpd/conf.d/deployment.config"

In this example:

  • We're using the files section to create a shell script that sets the keepAliveTimeout value in a temporary deployment config file.

  • The container_commands section is used to copy the temporary deployment config to the appropriate location in the server's configuration directory.

  1. Deploy your application to Elastic Beanstalk with the updated .ebextensions configuration.

This configuration file creates a script that sets the keepAliveTimeout to 75000 milliseconds (75 seconds) and appends it to a temporary deployment config file. Then, it copies this deployment config file to the appropriate location. This approach allows you to customize the Apache server's configuration, which is used to serve Node.js applications in Elastic Beanstalk.

Keep in mind that the exact paths and steps might vary depending on the specifics of your Elastic Beanstalk environment and the Node.js application configuration. Always test thoroughly after making changes to your environment configuration to ensure that it works as expected.

...