⬆️ ⬇️

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

From the translator: This is the twelfth, last article from the Node.js series from the Mozilla Identity team, which deals with 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’ll introduce 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 typical of PaaS without losing the flexibility of a customized infrastructure.



Using awsbox



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



The application needs to make the following changes:





Amazon credentials need to be specified in the environment variables AWS_ID and AWS_SECRET . They can be found in the Amazon management console.



After the configuration is completed, you can install the awsbox module via 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://<IP ADDRESS> ... 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://<IP ADDRESS> 3. ssh in with sudo: ssh ec2-user@<IP ADDRESS> 4. ssh as the deployment user: ssh app@<IP ADDRESS> 


The last step is the actual deployment of the application. This is done using git push :



 $ git push MyFirstAWSBOX HEAD:master 


Now your application is running on the EC2 virtual machine. The whole procedure takes about twenty minutes and requires minimal changes in the application. All changes in the development process can be laid out on the server in the usual way, via git push .



Now, after you have become familiar with the basic capabilities of awsbox, let’s go back a step and see how this module works.



Awsbox is a minimal contract



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



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



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


What software should I install? The list must be listed in package.json .



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



When creating awsbox, we wanted to make its impact on the application minimal so that it was 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 starts the application. Our image is based on Amazon Linux AMI - the Linux image provided by Amazon. The rpm package repositories and the yum package manager are available for this image. The specific image ID is specified in the awsbox code.



In the created instance of the machine there are several preset accounts. The ec2-user account is a server administrator with the ability to execute sudo. A proxy account is used to access a reverse HTTP proxy, which can be configured to enable SSL and support HTTPS without any changes to the application. Finally, the app account has access to your application, server logs, repository, and git hooks . He is responsible for installing dependencies and running the application.



Awsbox is command line tools



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



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



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



Awsbox is a bunch of functions and hooks.



Any server, except the most primitive, requires not only Node.js and Node packages. Awsbox allows you to specify system packages for installation using yum. For more fine-tuning, there are two ways:



SSH access . The goal of awsbox is to speed up deployment as much as possible, and sometimes it is easier and quicker to manually tweak some things without forgetting to mention these steps in the 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 anything else your application needs.



Is awsbox right for me?



Having a single application deployment mechanism for non-critical services greatly increased the performance of our team. A simple and understandable contract between the environment and the application greatly simplifies collaboration. The settled set of agreements simplifies the search and resolution of problems. Finally, the transition of the experimental application to production becomes easier when there is already a ready list of dependencies.



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






Source: https://habr.com/ru/post/198590/



All Articles