AWS CLI: A Beginners Guide(Part2)

High availability architecture

Create High Availability Architecture with AWS CLI.

  • Webserver configured on EC2 Instance
  • Document Root(/var/www/html) made persistent by mounting on EBS Block Device.
  • Static objects used in code such as pictures stored in S3
  • Setting up a Content Delivery Network using CloudFront and using the origin domain as an S3 bucket.
  • Finally, place the Cloud Front URL on the web app code for security and low latency.

So let's begin ✨

Step1:Creating an EC2 instance

aws ec2 run-instances --image-id ami-03cfb5e1fb4fac428 --count 1 --instance-type t2.micro --key-name taskKey --security-group-ids sg-02acd13d993724f96 --tag-specifications  ResourceType=instance,Tags=[{Key=Name,Value=myos},{Key=env,Value=testing}]
EC2 instance created

Step2:Create an EBS block storage and attaching to the instance

aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a
aws ec2 attach-volume --volume-id vol-089f493d3638f2341 --instance-id i-02ca1ad19d7a18f1a  --device /dev/sdf
EBS created and attached

Step 3:Configuring the instance

1. Listing the devices
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo fdisk -l”
2. Formatting device
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo mkfs.ext4 /dev/xvdf”
3. Installing HTTPD software
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo yum install httpd -y”
4. Mounting the formated drive
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo mount /dev/xvdf /var/www/html”
5. Checking the status of httpd
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo systemctl status httpd”
6. Starting the httpd service
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo systemctl start httpd”
7. Permenantly starting the service
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo systemctl enable httpd”
8. Again checking the status
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo systemctl status httpd”
9. Listing the active partition mounted
ssh -i taskKey.pem ec2-user@65.0.80.239 “sudo df -h”

Step4: Creating an S3 bucket and adding objects to it

aws s3api create-bucket --bucket cdntest3004 --acl public-read-write --region us-east-1
S3 bucket created
aws s3api put-object --acl public-read-write --bucket cdntest3004 --key /image/shirsha.jpeg --body C:\Users\hp\OneDrive\Desktop\vit\meh.jpeg
Image uploaded to the bucket

Step5: Creating CloudFront Distribution

aws cloudfront create-distribution --origin-domain-name cdntest3004.s3.amazonaws.com --default-root-object //image/shirsha.jpeg
CDN created

Step6: Creating a web app

ssh -i taskKey.pem ec2-user@65.0.80.239
sudo su
vim /var/www/html/my.html

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shirsha Datta

Shirsha Datta

I am a DevOps Enthusiast and recently taken to Cloud Computing. Learning Flutter App Development currently. In my free time I engage in competitive coding.