Horizontal Scaling in AWS
- Lets consider a scenario where we are running a web application in ec2.
- As the number of users grow we need to scale the ec2 instances.
- These scaled ec2 instances need to have the application preinstalled.
- Applications can be pre-installed in AMI ( Amazon Machine Image)
- As a first step in scaling, lets learn how to create an AMI with some website in it.
AMI
- AMI contains:
- OS
- pre-installed software
- configuration files
- AMI can be shared or can be private.
Steps
- Launch a Base instance (Base OS)
- install all the necessary softwares
- Remove sensitive data if any
- Create an AMI
- Share the AMI if necessary and copy the ami to other regions if required
- Note: Amazon identifies AMI by it id. AMI id is unique. Even if the AMI is copied to other region we get a new AMI id.
Building an AMI
- For ZayShop
- To run this website we require a linux instance with webserver (nginx/apache) and download the webdesign
- Note: As step 1 i will be creating this image in mumbai region
- Create a ubuntu 24.04 instance with t3.micro in mumbai region and execute the following commands
sudo apt update
sudo apt install nginx unzip -y
cd /tmp
wget https://templatemo.com/tm-zip-files-2020/templatemo_559_zay_shop.zip
unzip templatemo_559_zay_shop.zip
cd /tmp/templatemo_559_zay_shop
sudo cp -r . /var/www/html
- Navigate to the
http://<publicip>

- Now install stress
sudo apt install stress -y
- Now lets create an AMI


-
Wait for the status to be Ready
.
- Now lets delete the ec2 instance.
-
Now lets create a new ec2 instance and select the Zayshop ami which we have created.
- This approach of creating AMIs is easier, but not repeatable, we need to search for options to automate AMI creation.
- There are two popular ways of automation
- Packer by Hashicorp (Any Cloud)
- EC2 image builder (AWS)
EC2 Image Builder
- Image Builder automates building, testing and distributing AMIs
- To be discussed in next session
