Install Node.js On Elastic Beanstalk

Install

Amazon Beanstalk have some AMIs for Node.js applications. But if you are running a PHP/Ruby/Python/... application and you need node binary anyway for application, here is how you install it.

Node.js is available as a package on Amazon Linux but only through the Extra Packages for Enterprise Linux (EPEL) repository, so we can't install it with the section package of our .ebextension/*.config files. We have to run a command to install it.

# .ebextensions/myapp.config

# these commands run before the application and web server are
# set up and the application version file is extracted
commands:
  01_node_install:
    # run this command from /tmp directory
    cwd: /tmp
    # don't run the command if node is already installed (file /usr/bin/node exists)
    test: '[ ! -f /usr/bin/node ] && echo "node not installed"'
    # install from epel repository
    # flag -y for no-interaction installation
    command: 'yum install -y nodejs --enablerepo=epel'

See Amazon's documentation for more info.

Troubleshooting

Logs

Logs of the execution of .ebextension/*.config files are found in /var/log/cfn-init.log.

You should see something like

[DEBUG] Running command 01_node_install
[DEBUG] Running test for command 01_node_install
[DEBUG] Test command output: node not installed
[DEBUG] Test for command 01_node_install passed
[INFO] Command 01_node_install succeeded
[DEBUG] Command 01_node_install output: Loaded plugins: priorities, update-motd, upgrade-helper
872 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
...

Wrong package

To search for Node.js packages:

yum search node
Quentin Pleplé
May 2014