How to Create and Use Amazon Machine Images (AMI) π₯οΈβοΈ
What is an AMI? π€
An Amazon Machine Image (AMI) is essentially a blueprint for your instances on Amazon Web Services (AWS). Think of it as a snapshot of your setup, which you can use to create multiple instances with the same configuration. This makes scaling your infrastructure super easy! π±β¨
How to Create an AMI Image? π οΈ
Step 1: Create an Instance
- Launch an Instance:
- Configurations
- Name:
webserver
π₯οΈ - Operating System: Ubuntu π§
- Key Pair: Select or create a key pair π
- Security Group: Create a new security group named
webserver
π - Rules: Allow ports 22 (SSH) and 80 (HTTP) π
3. Set Inbound Rules:
Edit inbound rules to allow HTTP traffic from anywhere. π
4. Advanced Details:
Insert a Shell Script in user data while launching Instanceπ
#!/bin/bash
sudo apt update
sudo apt install wget net-tools unzip figlet apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
mkdir -p webfiles
cd webfiles
sudo wget https://www.tooplate.com/zip-templates/2118_chilling_cafe.zip
sudo unzip -o 2118_chilling_cafe.zip
sudo rm -rf /var/www/html/*
sudo cp -r 2118_chilling_cafe/* /var/www/html/
cd ..
sudo rm -rf webfiles
sudo systemctl restart apache2
figlet done
5. Launch:
Once the instance is running, you should be able to see your website. π
Step 2: Create the AMI Image
- Go to Your Instance:
- Select the instance you just created. π±οΈ
- Click on
Actions
>Image and templates
>Create image
. πΌοΈ
2. Configure the Image:
- Image Name:
chilling cafe
β - Description:
webserver
π - Tags: Add tags, e.g., Name:
chilling cafe
, Type:webserver
. π·οΈ
3. Create Image:
- Click
Create Image
and wait a few minutes for the process to complete. β³
You should now have an AMI snapshot of your instance! πΈ
Using Your AMI to Launch a New Instance π
- Launch New Instance:
- Use the AMI you just created (
chilling cafe
) to launch a new instance. π - Instance Name:
webserver2
π₯οΈ - Operating System: Select Ubuntu from
My AMIs
. π§
2.Launch:
- Complete the launch process and you should see the same website as before. πβ¨
Creating a Load Balancer βοΈ
Step 1: Create a Security Group for ELB
- Security Group Name:
ELB
π - Inbound Rules: Allow all traffic. π
Step 2: Configure Webserver Security Group
- Add Inbound Rule:
- Allow traffic from the ELB security group. π
- Name:
elb
βοΈ - Target Groups:
- Name:
chilling cafe
β - Instances: Include your instances (
webserver
andwebserver2
). π₯οΈπ₯οΈ - Health Checks: Ensure targets are healthy. β
3.Network Mapping:
- Use at least three availability zones (e.g.,
us-east-1b
,us-east-1c
,us-east-1e
). π‘
4.DNS Name:
- Once everything is set up and healthy, take the DNS name of your load balancer and place it in a new tab. You should see your website! ππ
Adding a CNAME Record in GoDaddy π·οΈπ
Step 4: Link Your Domain Name
1.Log in to GoDaddy:
- Navigate to your domain management page. π οΈ
- Select your domain,
bhargav.life
. π
2.Create a CNAME Record:
- Host:
coffee
β - Value: Paste the DNS name of your ELB here. π
- This will map
coffee.bhargav.life
to your load balancer. π
3.Save Changes:
- Save the CNAME record and wait for DNS propagation. This can take a few minutes to a few hours. β³
Once propagated, you can access your website using coffee.bhargav.life
. ππ
And there you have it! Youβve successfully created an AMI, used it to launch multiple instances, set up a load balancer to distribute traffic, and linked your custom domain. Happy cloud computing! βοΈπ