Tutorial: Deploying Scalable NodeJS app using ECS with Docker

Submitted By: Harkirat Singh, Harman Gill,Muhammad Imran Malik, Mauro Pappatera

 

 

Table of Contents

 

Tutorial Demo

This is a basic walk-through tutorial of how to deploy a webapp using ECS. In this tutorial, we will deploy a simple scalable nodejs app on docker containers but with ECS. With this, we will have our app run in a sandboxed environment in the form of docker container and using ECS, we can demonstrate how we can scale it better.

Demo of Working Application

In this demo, we will show you how to deploy a scalable,load-balanced and high available simple nodejs app. The demo will have multiple instances of nodejs app each running inside a container and load-balanced through haproxy. The basic architecture looks like following:



The app as a whole consists of four components that will be deployed:

  • Haproxy(for load-balancing)
  • App(Simple node JS app that prints out the port it started on)
  • MondoDB and Redis as backend

The demo will first walk-through setting ECS cluster from Web UI of AWS and later how to use ECS CLI.

i) Creating a ECS Cluster

First step in deploying any web application to create an ECS cluster from aws console. This is a fairly simple step as show in picture below:


ii) Install and Configure ECS CLI

Now that a bare minimum cluster is created its time to use ECS CLI. ECS CLI is a command line tool that you can use with given credentials to manage you cluster and prepare to run tasks and services on it.

Installing ECS CLI

To install the ECS CLI , simply download the ECS CLI binary as shown here


Configure the ECS CLI with credentials

Next step is to configure ECS CLI so that it stores our AWS credentials. Use your own AWS credentials with ECS CLI as:

ecs-cli configure --region us-west-2 --access-key --secret-key --cluster cs6320
INFO[0000] Saved ECS CLI configuration for cluster (cs6320)

iii) Creating the ECS Cluster from CLI

ECS CLI gives you full capability to create cluster from the CLI also.


iv) Use a docker-compose YAML file for task definition

Declaring tasks can be done from the Console or CLI. ECS CLI has a neat feature of supporting docker-compose , which are docker native way of declaring services. We avoided the hassle by reusing same compose based definitions as ECS CLI already supported them. The compose for our app looks like:


v) Start a task and services from YAML file

Now is the time to finally start our webapp from the compose file.


Once that’s successful, you will see the status using ecs cli.

vi) Verify cluster status and containers

Now we verify the status of containers by running “ps” command from ecs-cli as:


vii) Verify services and task from Console

We can also verify that all services are up and cluster status from console.


viii) Scaling to multiple web apps from ECS CLI

Scaling a webapp to multiple instances is simply one command. Lets say we want to scale to 5 , we can then issue the command as:

ecs-cli compose --file docker-compose.yml --project-name cs6320_1 scale 5


 


CS6320 Project 2 ECS Tutorial.

Submitted By:Harkirat Singh, Harman Gill,Muhammad Imran Malik, Mauro Pappatera