# I escalated my app to the cloud !

## Context :

I deployed a web app locally, and now I want to move it to the cloud for <mark>scalability, reliability, ease of management, and automation.</mark>

Here, I am using <mark>IaaS.</mark>

### **Major Services used will be** :

* ELB for Nginx
    
* EC2 instead of local vms
    
* Route 53 for DNS
    
* S3 for artifact storage
    
* Auto Scaling Group
    
* IAM
    
* ACM
    

## The Architecture changes :

![The Architecture](https://cdn.hashnode.com/res/hashnode/image/upload/v1720697331498/10cf0e6e-af3f-4f30-b144-1eb6c312ac02.png align="center")

> 1. The user will log in through an endpoint hosted on GoDaddy.
>     
> 2. They will access the endpoint via HTTPS, with the certificate managed by ACM.
>     
> 3. The user will connect to the ELB endpoint, which only permits HTTPS traffic.
>     
> 4. The ELB will then route the user to the application server.
>     
> 5. The application server consists of Tomcat instances, managed by an autoscaling group that adjusts based on traffic and only allows traffic on port 8080.
>     
> 6. The application server requires access to backend servers, managed by a Route 53 private hosted zone.
>     
> 7. These backend servers, which include MySQL, RabbitMQ, and Memcache, are in a separate security group and will only allow traffic on their specific ports.
>     

**I have a certificate ready in <mark>ACM</mark> issued by <mark>GoDaddy</mark>, which I obtained by requesting and adding a CNAME record.**

![godaddy cname record](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698065731/1a3161a9-1a60-463b-818b-c0b936bf0f55.png align="center")

![acm](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698097088/d9bd9beb-1715-4443-8a9e-fc8a41f483d8.png align="center")

## **Now I made 3 security groups:**

For the load balancer, allowing HTTP and HTTPS traffic.

For the app server, allowing port 8080 from the load balancer's security group. Also added SSH and port 8080 access from my IP.

For the backend, allowing port 3306 for MySQL, 11211 for Memcached, and 5672 for RabbitMQ from the app server's security group. Also allowed all traffic within the group and SSH for validation.

![security group](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698219004/d092cbde-577e-4d9a-a9a4-63fcf8f2ff75.png align="center")

## **I also have my key ready** :

![key](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698346197/8d84c2b3-7541-4716-bc76-269249aaf0b5.png align="center")

Cloned the <mark>repo</mark> and got the scripts for launching instances

![cloned repo](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698495703/782c120d-d642-47b2-ab81-0e990c624d7f.png align="center")

## Instances :

Launched DB, memcache, and RabbitMQ with Amazon Linux.

Launched the app server with Ubuntu.

Validated that all services and scripts are working

![ec2 instances](https://cdn.hashnode.com/res/hashnode/image/upload/v1720698573988/82c5253e-10fb-4af2-8e91-b9d08fe1ae47.png align="center")

### Created a **<mark>hosted zone</mark>** with simple routing rules by adding A records for backend servers using their private IPs.

![hosted zone](https://cdn.hashnode.com/res/hashnode/image/upload/v1720699137254/3f8068d2-efe7-4927-91bd-f3bc36fb6870.png align="center")

## <mark>Now, you need to build and upload the artifact.</mark>

Update the [application.properties](http://application.properties)file with the correct server routes. Built the arctifact locally using JDK and Maven.

![build](https://cdn.hashnode.com/res/hashnode/image/upload/v1720699319360/208425a7-66ba-4a28-8b4e-cdbea7a96fe9.png align="center")

create an **<mark>IAM user</mark>** to upload the artifact by creating an S3 bucket and pushing the artifact there.

![iam user](https://cdn.hashnode.com/res/hashnode/image/upload/v1720700421655/df459b1b-9405-4227-8529-00a245f53943.png align="center")

![aws config](https://cdn.hashnode.com/res/hashnode/image/upload/v1720700519405/cb23bb6b-ef21-478b-a37c-394a2f18e1db.png align="center")

![s3](https://cdn.hashnode.com/res/hashnode/image/upload/v1720700644074/1628fe5f-d70e-457f-9476-6e7b4775adbb.png align="center")

![artifact](https://cdn.hashnode.com/res/hashnode/image/upload/v1720700703141/9d0ee4f8-856c-4110-9f74-af26f495f895.png align="center")

Created an **<mark>IAM role</mark>** and gave access to the app server to download the artifact and start the Tomcat service for our app.

![i am role](https://cdn.hashnode.com/res/hashnode/image/upload/v1720700759157/43a930e4-63a1-4b02-b6e0-92bcd45de177.png align="center")

## Load Balancer :

Now, for setting up a **<mark>load balancer</mark>**, I created a **<mark>target group</mark>** and added our instance that listens on port 8080 as the target. I also set up a health check at `/login` on port 8080.

I then created an internet-facing application load balancer that is available on all subnets. It listens for both HTTP and HTTPS traffic by adding the target group and certificate.

![load balancer](https://cdn.hashnode.com/res/hashnode/image/upload/v1720701012436/e3cfc9c6-a3cb-46e2-a9a6-ab09c197c882.png align="center")

now, we have our application up and running when we add the elb endpoint to dns as a cname record

![loadbalancer endpoint](https://cdn.hashnode.com/res/hashnode/image/upload/v1720701065528/7d8c0ef9-de33-4669-86a2-332bbdad7798.png align="center")

## **<mark>Here's our working app with all services validated</mark>**

%[https://youtu.be/H1aIZtZ50sE] 

## Auto Scaling :

I wanted to make my app ready to scale up based on traffic. To add an auto-scaling group, I first created an **<mark>AMI</mark>** of my app instance.

![ami](https://cdn.hashnode.com/res/hashnode/image/upload/v1720701315267/ee081137-c8b8-4ba0-a210-bb49142312bc.png align="center")

created a <mark>launch template</mark> using the <mark>ami</mark>

Then, I created an **auto-scaling group** with desired triggers and added alarms using <mark>SNS</mark>.

![auto scaling group](https://cdn.hashnode.com/res/hashnode/image/upload/v1720701501670/3f9f6a6e-2dc1-4b49-a0d1-8bb432f3d00d.png align="center")

## ***<mark>And we are done, here is our webapp working, on cloud :</mark>***

![completed setup](https://cdn.hashnode.com/res/hashnode/image/upload/v1720701577904/1fb0a39a-0d4d-497a-a0a8-4437e47c98ac.png align="center")

> If you like what Im working on, leave some feedback in comments, a like would be great also subscribe to my newsletter for more such blog delivered straight to your inbox.

Thank you !
