Creating High Availability Architecture On AWS Using CLI

Creating High Availability Architecture On AWS Using CLI

In this article, I'll be providing a quite straightforward walkthrough for:

  • Deploying an Apache web server on an AWS EC2 instance
  • Using an EBS volume for the document root (/var/www/html)
  • Uploading our site's static content to an AWS S3 bucket
  • Using CloudFront CDN for fast content delivery across regions


Step 1: Create a security group for the web server.

No alt text provided for this image

Step 2: Add inbound rules for SSH and HTTP ports.

No alt text provided for this image

Step 3: Launch an EC2 instance with RHEL8 AMI and assign your newly created security group to it.

No alt text provided for this image

Step 4: Log into the instance through SSH and install the Apache web server using yum install httpd

No alt text provided for this image

Step 5: Enable the httpd service using systemctl enable httpd to automatically launch it during the instance startup, and then start the httpd service using systemctl start httpd

No alt text provided for this image

Step 6: Check if the web server is working by using the Public IP of the instance, which can be found using aws ec2 describe-instances --instance-ids <your_instance_id>

It's 13.126.140.168 in my case, and the default website looks like below:

No alt text provided for this image

Step 7: Once the web server is up and running, create an EBS volume, attach it to the instance, format it with ext4 filesystem, and then mount it on the document root directory, i.e., /var/www/html

I've already discussed each of these steps in this article, so please go through it in case your need help with it.

Once that's done, you can verify if the volume has been mounted on the document root by using df -h

No alt text provided for this image

Step 8: Now, you need to create an S3 bucket to store the site's static content. To create a bucket, you can use aws s3 mb command, and to upload a file to the bucket, you can use aws s3 cp command.

Both of these are demonstrated below:

No alt text provided for this image

Step 9: Create a CloudFront distribution with the S3 bucket's domain name as the origin domain name. The CloudFront domain name generated in this case has been highlighted below:

No alt text provided for this image

Step 10: To test if the CloudFront distribution is working, simply copy CloudFront the domain name generated in the previous step and add the location of the static image file uploaded in S3 at the end of it, as shown below:

No alt text provided for this image

Step 11: Now, create the index.html file for your website in the document root and use the CloudFront link to display the static image file uploaded in your S3 bucket on your website.

No alt text provided for this image


Final Outcome

Once all the steps mentioned above have been executed successfully, you can test your website by using the Public IP of your web server's instance.

No alt text provided for this image


For a detailed guide on using AWS CLI commands, please refer to the AWS CLI Command Reference

To view or add a comment, sign in

More articles by Abhinav Sinha

Explore content categories