Awsbox - PaaS infrastructure for deploying Node.js applications in the Amazon cloud

Original author: Lloyd Hilaiel
  • Transfer
  • Tutorial
From a translator: This is the twelfth, last article in the Node.js series from the Mozilla Identity team, which is involved in the Persona project .

After you wrote the application on Node.js, how to deploy it on the server? Instead of using a ready-made PaaS solution, our team created its own infrastructure on top of Amazon EC2. Now we will tell you more about how we did it.

We present you awsbox - a minimalistic layer of PaaS infrastructure for Node.js, which now serves a couple of dozen non-critical Mozilla services. Awsbox is designed to provide the simplicity and ease of deployment specific to PaaS without losing the flexibility of a custom infrastructure.

Using awsbox

To start using awsbox, you'll need to make a few small changes to your application and add Amazon credentials to your environment variables. After that, you can start the deployment using the command line tools.

The application needs to make the following changes:

  • create a file .awsbox.jsoncontaining instructions for starting the server;
  • awsbox add to the list of dependencies package.json;
  • make sure that the server is listening on the port specified in the environment variable PORT.

Amazon credentials must be specified in AWS_IDand environment variables AWS_SECRET. You can find them in the Amazon management console.

After the configuration is completed, you can install the awsbox module through npm and create a server:

$ node_modules/.bin/awsbox create -n MyFirstAWSBOX
reading .awsbox.json
attempting to set up VM "MyFirstAWSBOX"
   ... VM launched, waiting for startup (should take about 20s)
   ... Instance ready, setting human readable name in aws
   ... name set, waiting for ssh access and configuring
   ... public url will be: http://
   ... nope.  not yet.  retrying.
   ... victory!  server is accessible and configured
   ... applying system updates
   ... and your git remote is all set up
   ... configuring SSL behavior (enable)
Yay! You have your very own deployment. Here are the basics:
  1. deploy your code:  git push MyFirstAWSBOX HEAD:master
  2. visit your server on the web: http://
  3. ssh in with sudo: ssh ec2-user@
  4. ssh as the deployment user: ssh app@

The final step is to actually deploy the application. This is done using git push:

$ git push MyFirstAWSBOX HEAD:master

Your application now runs on the EC2 virtual machine. The whole procedure takes about twenty minutes and requires minimal changes to the application. All changes in the development process can be uploaded to the server in the usual way, through git push.

Now, after you become familiar with the basic features of awsbox, let's take a step back and see how this module works.

Awsbox is a minimalistic contract

Any working server environment has certain requirements for the launched application, in other words, concludes a contract with it. For awsbox, the main points of the contract are:

What processes will be launched? This should be stated in .awsbox.json. In its simplest form, it looks like this:

  "processes": [ "path/to/myprocess.js" ]

What software do you need to install? The list must be listed in package.json.

Which port should the server listen to? The port number must be in an environment variable PORT.

When creating awsbox, we wanted to make its impact on the application minimal so that it would be easy to port existing applications.

Awsbox is a virtual machine image

During installation, awsbox creates an instance of the virtual machine from the image, installs the dependencies, and launches the application. Our image is built on the basis of Amazon Linux AMI - the Linux image that Amazon provides. The rpm package repositories and the yum package manager are available for this image . The specific image ID is listed in awsbox code.

There are several predefined accounts in the created machine instance. An account ec2-useris a server administrator with the ability to execute sudo. The account proxyis used to access the reverse HTTP proxy, which can be configured to enable SSL and support HTTPS without any changes in the application. Finally, the account apphas access to your application, server logs, repository andhukam git . He is responsible for installing dependencies and running the application.

Awsbox are command line tools

When you install awsbox, you get a set of JavaScript libraries and command line tools on the local machine. Scripts and console commands allow you to deploy the application much faster than through the Amazon web console, and take on most of the work of creating an EC2 instance accessible from the web and via SSH.

In addition, awsbox provides many commands for administering your application server, a complete list of which can be viewed by running node_modules/.bin/awsbox -h.

The most interesting team from this set is create. She creates a virtual machine.

Awsbox is a bunch of features and hooks

Any server, except the most primitive one, requires not only Node.js and Node packages. Awsbox allows you to specify system packages to install using yum. For finer tuning, there are two ways:

SSH access . The goal of awsbox is to speed up deployment as much as possible, and sometimes it’s easiest and fastest to manually configure some things without forgetting to mention these steps in README. But something can be automated.

Scripts for automatic configuration . Awsbox provides hooks that allow you to add a custom script at certain stages of the installation. With their help, you can configure MySQL , install Redis - or whatever else your application needs.

Does awsbox suit me?

Having a single application deployment mechanism for non-critical services greatly increased the productivity of our team. A simple and understandable contract between the environment and the application greatly simplifies the collaboration. A well-established set of conventions simplifies troubleshooting. Finally, moving an experimental application into production becomes easier when you already have a list of dependencies ready.

If you are looking for a solution to deploy your own Node.js experimental services, you should take a look at awsbox.

Also popular now: