Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

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. For an example walkthrough using configuration files, see Deploying an Express Application to Elastic Beanstalk.

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.


    Configuration files should conform to YAML or JSON formatting standards. For example, indentation is critical to the proper interpretation of YAML. For more information, go to http://www.yaml.org/start.html or http://www.json.org, respectively. For more information about using configuration files to deploy an application to Elastic Beanstalk, see Using Configuration Files.

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

    # If you do not specify a namespace, the default used is aws:elasticbeanstalk:application:environment
      - option_name: AWS_SECRET_KEY
        value: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
      - option_name: AWS_ACCESS_KEY_ID
      - namespace: aws:elasticbeanstalk:container:nodejs
        option_name: ProxyServer
        value: nginx
      - namespace: aws:elasticbeanstalk:container:nodejs:staticfiles
        option_name: /public
        value: /public 


    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, go to Requirements files. 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 an Express application, see Deploying an Express Application to Elastic Beanstalk and Deploying an Express Application with Clustering to Elastic Beanstalk. 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.



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 Container 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

    content: |
      gzip_types application/json;

Example 2. Example configuring Apache

    content: |
      AddOutputFilterByType DEFLATE application/json