Scaling a MEAN App in Lightsail Using App Tiers

1.5 hours
  • 4 Learning Objectives

About this Hands-on Lab

In this learning activity, we will implement the MEAN stack using a multi-instance architecture. We will then scale the architecture, first by separating the app and database tiers, and then by scaling the app tier using a load balancer.

The goal of this learning activity is to gain experience with:

* Creating a Lightsail instance complete with a pre-installed stack
* Using a launch script to perform advanced configuration
* Interacting with an on-instance MongoDB
* Connecting to an instance to configure a MEAN-based application
* Application testing and verification
* Using multi-instance applications
* Using snapshots to clone instances
* Using load balancers to enable mass scaling

#### Helpful Links:

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Deploy an instance-based MongoDB.
  1. Deploy an instance with 2 GB of memory using the Ubuntu OS Only blueprint.
  2. Name the instance mongo.
  3. Use the following launch script to configure the database:
  4. When the instance is built, log in using SSH and check that the database is running.
    mongo --host $(hostname -i)
    show dbs
  5. Note the private IP of the instance; we will need it later.

Note: ipconfig -a can show the private IP of the Mongo instance. The public IP is shown for the instances on the box that represents each instance.

Deploy the application front end on an instance.
  1. Deploy a new instance using the 512 MB ram size.
  2. Name the instance node-fe-1.
  3. Use the Node.js blueprint (we don’t need an on-instance database, and the app will install everything it needs).
  4. Use the following launch script:
  5. When the instance finishes building, we need to point it at the database server. Log in to the node-fe-1 instance using SSH and run:
    cd ~/todo
    sudo sh -c "cat > ./.env"  << EOF
  6. Next, we need to make the application auto-start and do a final configuration.
    sudo pm2 startup ubuntu
    sudo pm2 start /home/bitnami/todo-mean/bin/www 
    sudo pm2 save
  7. Then we need to show the logs to ensure everything is working correctly.
    sudo pm2 logs www
  8. Once the logs are streaming, navigate to http://<frontendinstanceip> to test the application.
Clone and scale the front end.

Snapshot the Working Front-End Instance

  1. Click the context (...) menu for the node-fe-1 instance.
  2. Choose Manage, then Snapshots.
  3. Create a snapshot and wait for it to complete.

Create Additional Front-End Instances

  1. Locate the snapshot. Click the context (...) menu and select Create New Instance.
  2. Name the instance node-fe-2.
  3. Repeat this process to create a new front-end instance called node-fe-3.
  4. Navigate to each new instance’s public IP and test that the application works.
  5. Create a task on one instance, and make sure it’s visible on all instances.
Distribute traffic across the front end with a load balancer.
  1. Create a load balancer and name it todo-lb.
    • Once available, attach all front-end instances to the load balancer (node-fe-1, node-fe-2, and node-fe-3).
    • Ensure that health checks are enabled.
    • Make sure each instance passes health checks.
    • When all instances are healthy, locate the load balancer DNS name and open it in a browser.
    • If no task exists, create one.
    • Refresh the page and ensure the task still exists. Note the hostname changes at the bottom showing which front-end instance is being used.

Additional Resources

Make sure you are in the us-east-1 region. Use the provided credentials to log in to the AWS management console.

Follow the steps below. You can either attempt to follow the steps on your own and then watch the videos to verify your solution or follow along with the videos to complete the tasks — the choice is yours.

Note: ipconfig -a can show the private IP of the Mongo instance. The public IP is shown for the instances on the box that represents each instance.

Click the question marks below to view more details for each task.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?