How to create High Availability Architecture with AWS CLI
4 min readNov 3, 2020
In this article … We will continue our journey as to how we can create a high availability architecture using the concept of Content Delivery Network ( CDN ) via a service of AWS known as CloudFront using 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.
→ First launching an EC2 instance with existing key pair and security group. ( Use the below command )
aws ec2 run-instances --security-group-ids group_id --instance-type type_of_instance --image-id bootable_image_id --key-name name_of_the_key --count no._of_instances
→ Verify from WebUI whether instance is launched and running or not :
→ Creating an EBS volume ( Use the below command )
aws ec2 create-volume --volume-type gp2 --size size_of_volume --availability-zone zone_name
→ Attaching the above created volume to our launched instance (Use the below command)
aws ec2 attach-volume --volume-id id_of_volume_created --instance-id id_of_instance --device /dev/sdf
→ Now you can enter the terminal of your launched instance via SSH or Putty
→ Running the fdisk -l command on the terminal to list the disks and devices on our system
→ Now , let’s install , configure and start the webserver service or program ,i.e., httpd service
Commands to be used :
→ yum install httpd
→ systemctl start httpd
→ Now before storing any data in the folder that is generally accessed by the webserver , we need to create a partiton , format and mount our attached EBS disk or volume , so that our data can be made persistent …
Commands for these :
→ fdisk <device name>
n , p , 1 , w
→ mkfs.ext4 <device name>
→ mount <device name> <folder name>
→ Next , let’s create an S3 bucket and also set its permission using AWS CLI . ( Use the below commands )
aws s3api create-bucket --bucket <bucket name> --region <region name> --create-bucket-configuration LocationConstraint=<region name>
NOTE : If we want to create our S3 bucket in region other than us-east-1 using AWS CLI we need to use the create bucket configuration option .
aws s3api put-bucket-acl --bucket <bucket name> --grant-read uri:http://acs.amazonaws.com/groups/global/AllUsers
→ Verify it from the WebUI as to whether the bucket is created or not
→ Put an object ( in this case an image file ) inside the above created bucket and also set its access details [ Use the below commands ]
aws s3api put-object --bucket <bucket name> --key <any key name for the object> --body <path of the object in our local system>