Byte Introduction

Deploy your first app server

Skills:

Web Server

Objective

Do your first app server backend deployment in AWS!

Background

Cloud

Buzz word that everyone uses, but is a very simple concept. In very simple terms,

  • Cloud is a bunch of hardware resources like storage or compute that someone maintains for you.

  • Eg: Apple maintains your photos in iCloud instead of your harddisk, AWS provides you with a server (think desktop computer) to host your website instead of doing it from a machine at your house.


AWS

Amazon Web Services (AWS) is one of the most popular cloud service providers out in the market. They provide different kinds of services for companies and individuals.

Some of the popular offerings from AWS are:

  • Virtual machines (EC2)

    • VM - in simple terms, computers with some configuration; eg: 2cpu, 16GB RAM, 20 GB hard disk
  • Storage (S3)

  • Load Balancers (ELB)

You’ll be using AWS EC2 virtual machines in this Byte.


Docker

Docker is a containerization technology - you can think of them as tiny VMs. You don’t have to know the details of docker for this Byte. But feel free to dig deeper if you are curious.

Primary goals

  1. Launch your first virtual server in AWS

  2. Deploy the app backend server

  3. Connect mobile app to the app backend server

Objective

Do your first app server backend deployment in AWS!

Background

Cloud

Buzz word that everyone uses, but is a very simple concept. In very simple terms,

  • Cloud is a bunch of hardware resources like storage or compute that someone maintains for you.

  • Eg: Apple maintains your photos in iCloud instead of your harddisk, AWS provides you with a server (think desktop computer) to host your website instead of doing it from a machine at your house.


AWS

Amazon Web Services (AWS) is one of the most popular cloud service providers out in the market. They provide different kinds of services for companies and individuals.

Some of the popular offerings from AWS are:

  • Virtual machines (EC2)

    • VM - in simple terms, computers with some configuration; eg: 2cpu, 16GB RAM, 20 GB hard disk
  • Storage (S3)

  • Load Balancers (ELB)

You’ll be using AWS EC2 virtual machines in this Byte.


Docker

Docker is a containerization technology - you can think of them as tiny VMs. You don’t have to know the details of docker for this Byte. But feel free to dig deeper if you are curious.

Primary goals

  1. Launch your first virtual server in AWS

  2. Deploy the app backend server

  3. Connect mobile app to the app backend server

Create an AWS account

Create an EC2 instance

Elastic Cloud (EC2) is Amazon’s version of compute service - in other words, you can create VMs in EC2 with a configuration of your choice.


Step 1. Click on the search bar. Search for EC2. After clicking you will see a EC2 dashboard. Click on the launch instance button.

image alt text

Step 2. Select Ubuntu 18 64 bit (x86).

image alt text

Step 3. Click on t2 micro (Free Tier) with 1 GiB memory. Click Next Configure Instance Details.

image alt text

Step 4. Choose the number of instances as 1 and click default subnet in any available zone. Move to the next step, Click on Add storage.

image alt text

Step 5. Leave this at default. Click on Add tags.

image alt text

Step 6. Write Name in the Key and write anything in the value and that value will be your Instance name. Click on configure security group.

image alt text

Step 7. Open ports 22, 80, 8081 for ssh & QEats. Click on review and launch.

image alt text

Step 8. Click on Create a new key pair. Give a key-pair name, download it. After that click on launch and wait for a few minutes to launch our instance.

image alt text

Step 9. After launching, you will see a screen like this. Click on View Instances to go to the Instances window.

image alt text

Step 10. If you want to stop/terminate/reboot your instance. You can do it anytime.

image alt text

SSH into your instance

Change mode of your pem file you downloaded in the previous task.


# Usually downloads go to ~/Downloads/

chmod 400 <path-to-your-pem-file>

ssh -i "crio-demo.pem" ubuntu@<your-ec2-url>


# Example

ssh -i "~/Downloads/crio-demo.pem" ubuntu@ec2-13-233-100-101.ap-south-1.compute.amazonaws.com

Deploying app backend server

You will be deploying the app backend for QEats app - which is a Swiggy/UberEats like food-ordering app. Once you start the backend server, you can connect to it from your app anywhere in the world and have some fun.



Type the following instructions the AWS instance terminal -


# 1. Installing Docker

# APT is a packet manager in Linux

# Following instructions are similar to installing an EXE file in windows or an app in Android.

sudo apt-get update

sudo apt-get install wget

wget -qO- https://get.docker.com/ | sh

sudo usermod -aG docker $USER

sudo service docker start

newgrp docker


# 2. Install telnet

sudo apt install -y telnet


# 3. Run the docker container for QEats app server.

# You are exposing your server on port 8081 - so make sure your firewall rules allow incoming connections on this port.

sudo docker run -d -m 800m -v /tmp/container:/tmp:rw -p 8081:8081 criodo/qeats-server

The moment you run the above command, you will start seeing something like:

image alt text

It will take a few minutes as it is downloading all the necessary images from Dockerhub which is a public repository of docker images. Think of Dockerhub as App store for docker images. For the purposes of this Byte, you don’t have to understand all the docker instructions, but feel free to refer to the reference material if you like to learn more :)


Once download, finishes, your server will start serving data on port 8081!


Checkpoint

Type telnet localhost 8081 from the same AWS instance and you should see the following output if everything worked fine -

image alt text

You can press Ctrl + ] and then type quit to return back to terminal.


If there are any issues in starting your server, you will see this:

image alt text

In that case, you might have to retry the instructions.

Connect the QEats Android app with your server

Download the QEats Android App (APK) here onto your phone and install it. If you don’t have an Android phone, you can use an online Android emulator as shown in the next section.


The login screen of the QEats app looks like this.

image alt text

Enter the following details to connect to the QEats backend server:

  • Username: crio-user

  • IP Address: AWS instance public ip

  • Port number: 8081

  • Phone number: optional field

You will start seeing restaurants - you can start playing around with search, placing orders etc from the app.

Running QEats app on Emulator

Takeaways

You have successfully deployed your first app server on AWS EC2 instance using Docker.


Congratulations! You can ask your friends to install QEats app and connect to your server. Boast away!

Note

Make sure to terminate the instance once you play around with it!

Curious Cats

Once you host it on the server, you can connect to it through browser and Android / iOS apps available in Playstore. Note that you may have to change firewall settings to allow port 8065

Newfound Superpowers

You now know what cloud is and what it is used for. It is no more a mystery word to you.

Now you can

  • Participate in discussions when your peers talk about cloud computing

  • Create VMs of any configuration and host a server there - are you thinking of a website already :)

Next Steps

Was deploying the app server for QEats fun?


How about building the app server all by yourself :)


Try out the Java Backend Developer experience - https://crio.do/backend-developer-experience