👨‍💻Creating High Availability Architecture with AWS CLI Using {EC2, Webserver, EBS, S3, CloudFront}👨‍💻

Task Description📄

🔰 Create High Availability Architecture with AWS CLI 🔰

🔅The architecture includes-

- 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 Content Delivery Network using CloudFront and using the origin domain as S3 bucket.

- Finally place the Cloud Front URL on the webapp code for security and low latency.


  • Commands to create credential and to create key pair :-

>> aws configure

>>aws ec2 create-key-pair — key-name Ravikey756

  • You will see a new key pair of name “Ravikey756” is created in aws account.

STEP2️⃣ :- Create a Security Group

  • command to create security group:-

>> aws ec2 create-security-group — group-name Ravi_SG — vpc-id vpc-824eaee9 — description “Ravi Security Group Created from cli”

  • Let’s check Security Group is created or not.
  • Grt🎉 Security Group is successfully created.

STEP3️⃣ :- Launch an EC2 Instance

  • Command to launch an Instance:-

>> aws ec2 run-instances — image-id ami-0eeb03e72075b9bcc — instance-type t2.micro — count 1 — subnet-id subnet-c7e9e0af — security-group-ids sg-03b970c87a375039d — key-name Ravikey756

  • Command run successfully and in webui we can see that one new instance is recently launched.

STEP4️⃣ :- Configure above created instance as Webserver

  • For configuring as Webserver we have to 1st install httpd software using below command.

>> yum install httpd

  • Now, We have to start the services of the Software, we can start services by using command.

>> systemctl start httpd

STEP5️⃣ :- Create an EBS volume

  • command to create EBS volume using cli is as :-

>> aws ec2 create-volume — volume-type gp2 — availability-zone ap-south-1a — size 1

  • Check in WebUI whether EBS volume is created or not.

STEP6️⃣ :- Attach EBS volume to EC2 Instance

  • command to attach EBS volume to EC2 Instance is :-

>> aws ec2 attach-volume — instance-id i-054862801d20ae943 — volume-id vol-0f679436de5170dde — device /dev/sdf

  • In WebUI we can see that EBS volume is successfully attached with EC2 Instance.

STEP7️⃣ :- Partitioned and Format the EBS volume

  • Before using recently attached EBS volume, we have to first partitioned and format it.
  • Command to create the Partition is :-

>> fdisk /dev/xvdf

  • By using command “ fdisk -l ” we can check that partition is created or not.
  • Belove command will help you to Format the partition.

>> mkfs.ext4 /dev/xvdf1

  • After formatting the only thing which is remain is mount, we have to mount the partition with folder “ /var/www/html ”
  • Command to mount the partition with folder is :-

>> mount /dev/xvdf1 /var/www/html

  • Now, Partition is been Successfully Formatted ❗❗

STEP8️⃣ :- Create a S3 Bucket

  • Command to create S3 Bucket is :-

>> aws s3api create-bucket — bucket <bucket_name> — region <Region_code> — create-bucket-configuration LocationConstraint = <region_code>

  • In WebUI we see an arthawstask6 named bucket is created.
  • Now, put an image in this bucket by using command :-

>> aws s3 cp D:\task6\VimalSir.jpeg s3://arthawstask6/

  • we can see image on AWS WebUI.
  • Now, lets create a task.html file , write some code in it and also add image url from s3 Storage.
  • Now, next we have to open browser and put “<public_ip of the instance>/html_filename” on the url_bar.
  • we will see ❤❤ 👇👇

STEP9️⃣ :- Create a CloudFront Distribution with the origin as S3 object URL

  • As we observe that by using S3 Storage URL we have to face the issue of latency so to overcome the issue of low latency we have to use CloudFront which will store cache’s at near-by edge location and then we can access it frequently.
  • Command to create a CloudFront Distribution is :-

>> aws cloudfront create-distribution — origin-domain-name arthawstask6.s3.amazonaws.com

  • In WebUI we will see a CloudFront Distribution is created and also one Domain name is created.
  • We have to use this Domain Name at the place of image url in task6,html file.
  • Again, put the public ip with file_name in the search bar in browser you wil see the result.
  • Output is same but this time you will get output fastly.

I would like to thanks Everyone’s for coming here and reading my blog❗❗❗

If you really like it & want to appreciate me then Clap👏 & Share it to all of your connection.



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