Menu
AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Configuring Your AWS Elastic Beanstalk Node.js Environment

You can fine-tune the behavior of your Amazon EC2 instances by using a configuration file to configure your container settings. For a list of container options, see Node.js Platform Options.

The Container/Node.js Options configuration also lets you fine-tune the behavior of your Amazon EC2 instances and enable or disable Amazon S3 log rotation. You can edit the Elastic Beanstalk environment's Amazon EC2 instance configuration with the AWS Management Console.

Customizing and Configuring a Node.js Environment

When deploying your Node.js application, you may want to customize and configure the behavior of your EC2 instances. You can easily customize your instances at the same time that you deploy your application version by including a configuration file with your source bundle. This section walks you through the process of creating a configuration file and bundling it with your source.

To customize and configure your Node.js environment

  1. Create a configuration file with the extension .config (e.g., myapp.config) and place it in an .ebextensions top-level directory of your source bundle. You can have multiple configuration files in your .ebextensions directory. These files are executed in alphabetical order. For example, .ebextensions/01run.config is executed before .ebextensions/02do.config.

    Note

    YAML relies on consistent indentation. Match the indentation level when replacing content in an example configuration file and make sure that your text editor uses spaces, not tab characters, to indent.

    The following is an example snippet of a configuration file. For a full list of Node.js container options, see Node.js Platform Options.

    option_settings:
      - namespace: aws:elasticbeanstalk:container:nodejs
        option_name: ProxyServer
        value: nginx
      - namespace: aws:elasticbeanstalk:container:nodejs:staticfiles
        option_name: /public
        value: /public

    Note

    You can specify any key-value pairs in the aws:elasticbeanstalk:application:environment namespace, and they will be passed in as environment variables on your EC2 instances.

  2. Create a package.json file and place it in the top-level directory of your source bundle. A typical Node.js application will have dependencies on other third-party packages. You specify all the packages you need (as well as their versions) in a single package.json file. For more information about the requirements file, see package.json on the NPM website. The following is an example package.json file for the Express framework.

    {
      "name": "application-name",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node app"
      },
      "dependencies": {
        "express": "3.1.0",
        "jade": "*",
        "mysql": "*",
        "async": "*",
        "node-uuid": "*"
      }
    }
  3. Deploy your application version.

For an example walkthrough of deploying a Geddy application with Amazon ElastiCache, see Deploying a Geddy Application with Clustering to Elastic Beanstalk.

Accessing Environment Configuration Settings

Inside the Node.js environment running in AWS Elastic Beanstalk, you can access the environment variables using process.env.ENV_VARIABLE similar to the following example.

process.env.PARAM1
process.env.PARAM2

Note

Environment configuration settings can contain any printable ASCII character except the grave accent (`, ASCII 96) and cannot exceed 200 characters in length.

For a list of configuration settings, see Node.js Platform Options.

Example: Using Configuration Files to Configure nginx and Apache

You can use configuration files to make modifications to Apache. For example, if you want to configure nginx or Apache to server application/json gzipped, which is not on by default, you would create a configuration file with the following snippets.

Example 1. Example configuring nginx

files:
  /etc/nginx/conf.d/gzip.conf:
    content: |
      gzip_types application/json;

Example 2. Example configuring Apache

files:
  /etc/httpd/conf.d/gzip.conf:
    content: |
      AddOutputFilterByType DEFLATE application/json

AWS Management Console

The Node.js settings lets you fine-tune the behavior of your Amazon EC2 instances and enable or disable Amazon S3 log rotation. You can edit the Elastic Beanstalk environment's Amazon EC2 instance configuration using the AWS Management Console.

To access the Node.js container configurations for your Elastic Beanstalk application

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management console for your environment.

  3. Choose Configuration.

  4. In the Software Configuration section, choose Edit.

Container Options

On the configuration page, specify the following:

  • Proxy Server–Specifies which web server to use to proxy connections to Node.js. By default, nginx is used. If you select none, static file mappings do not take affect, and gzip compression is disabled.

  • Node Version–Specifies the version of Node.js. For information about what versions are supported, see Supported Platforms.

    Note

    When support for the version of Node.js that you are using is removed from the platform configuration, you must change or remove the version setting prior to doing a platform upgrade. This may occur when a security vulnerability is identified for one or more versions of Node.js

    When this occurs, attempting to upgrade to a new version of the platform that does not support the configured NodeVersion will fail. To avoid needing to create a new environment, change the NodeVersion configuration option to a version that is supported by both the old configuration version and the new one, or remove the option setting, and then perform the platform upgrade.

  • Gzip Compression–Specifies whether gzip compression is enabled. By default, gzip compression is enabled.

  • Node Command–Lets you enter the command used to start the Node.js application. An empty string (the default) means Elastic Beanstalk will use app.js, then server.js, and then npm start in that order.

Log Options

The Log Options section has two settings:

  • Instance profile– Specifies the instance profile that has permission to access the Amazon S3 bucket associated with your application.

  • Enable log file rotation to Amazon S3–Specifies whether log files for your application's Amazon EC2 instances should be copied to your Amazon S3 bucket associated with your application.

Static Files

To improve performance, you may want to configure nginx or Apache to server static files (for example, HTML or images) from a set of directories inside your web application. You can set the virtual path and directory mapping on the Container tab in the Static Files section. To add multiple mappings, click Add Path. To remove a mapping, click Remove.

Environment Properties

The Environment Properties section lets you specify environment configuration settings on the Amazon EC2 instances that are running your application. These settings are passed in as key-value pairs to the application.

Accessing Environment Configuration Settings

Inside the Node.js environment running in AWS Elastic Beanstalk, you can access the environment variables using process.env.ENV_VARIABLE similar to the following example.

process.env.PARAM1
process.env.PARAM2

Note

Environment configuration settings can contain any printable ASCII character except the grave accent (`, ASCII 96) and cannot exceed 200 characters in length.

For a list of configuration settings, see Node.js Platform Options.