| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
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 AWS Elastic Beanstalk.
To customize and configure your Node.js environment
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. For information about the file
format and contents of the configuration file, 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_settings:
- option_name: AWS_SECRET_KEY
value: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- option_name: AWS_ACCESS_KEY_ID
value: AKIAIOSFODNN7EXAMPLE
- 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.
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": "*"
}
}Deploy your application version.
For an example walkthrough of deploying an Express application, see Deploying an Express Application to AWS Elastic Beanstalk and Deploying an Express Application with Clustering to AWS Elastic Beanstalk. For an example walkthrough of deploying a Geddy application with Amazon ElastiCache, see Deploying a Geddy Application with Clustering to AWS Elastic Beanstalk.
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
For a list of configuration settings, see Node.js Container Options.
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