Create High Availability Architecture with AWS CLI

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.

Step 1:

Create an IAM user to access AWS CLI. Then use the following command to access the AWS service through CLI,

aws configure

No alt text provided for this image

Then create a key pair to launch an instance

aws ec2 create-key-pair --key-name <key_name>


No alt text provided for this image
No alt text provided for this image

Launching an instance.

aws ec2 run-instances --image-id <imageid> --instance-type <instancetype> --key-name <keyname> --security-group-ids <securitygroupid>

No alt text provided for this image
No alt text provided for this image

Step 2:

Create an EBS volume

aws ec2 create-volume --availability-zone <region_name> --size <size>

No alt text provided for this image
No alt text provided for this image

Attach an EBS volume to the launched instance,

aws ec2 attach-volume --instance-id <instance id> --volume-id <ebs volumeid> --device <device name>

No alt text provided for this image
No alt text provided for this image

Step 3:

Install Apache Server On The Instance

yum install httpd

No alt text provided for this image

Start the Service,

systemctl start httpd


No alt text provided for this image

Step 4:

Create a Partition on the attached EBS volume:

fdisk /dev/xvdf

No alt text provided for this image
No alt text provided for this image

Format the partition:

mkfs.ext4 /dev/xvdf1

No alt text provided for this image

Mount the Partition:

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

lsblk
No alt text provided for this image

Step 5:

Create a S3 Bucket,

aws s3api create-bucket --acl public-read-write --bucket <bucket name> --region <region name> --create-bucket-configuration LocationConstraint=<region name>

No alt text provided for this image
No alt text provided for this image

Upload your picture to the S3 Bucket

aws s3 cp <image name> <url>

No alt text provided for this image
No alt text provided for this image

Step 6:

Create a Cloud Front Distribution:

aws cloudfront create-distribution --origin-domain-name <s3 domain name>


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 7:

Go to the path /var/www/html in your instance and create an .html file and add the cloud front URL in your script

No alt text provided for this image

Now lets take a look at our Web page

http://<instance ip>/filename.html

No alt text provided for this image

webpage is ready with great Security and Low latency

Thanks for reading


To view or add a comment, sign in

More articles by Harneet singh

Others also viewed

Explore content categories