✳️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.
For this task you can first read my blog on how to create keys, security groups etc using the aws cli here.
Now we will move to the task as described and we will first create an ebs volume of 5Gib using the aws cli.
Use the command as shown above for creating the volume of 5Gib in a specific availability zone.
After creating the volume we will now launch an instance using the cli
For changing the instance key name use the following command
As you can see the we do not have attached the ebs volume to the webserver root directory(/var/www/html/).
We will now attach the ebs volume to the instance, so that we can use this volume as a pen drive and can use the data in different instances.
After attaching the volume we first need to format the volume.
use fdisk -l (to list the volumes attached)
you can check my previous blog for better understanding about formating..
We will then mount the volume to the root directory.
For better understanding of the above method you can check it on my previous blog as I have explained about it their.
Now we will move to the next part where we will create our S3 bucket using the aws cli and then use the cloudfront services to provide our data in different edge locations their.
For using the S3 services in cli you need to give the user AmazonS3FullAccess role to the IAM user.
Go to IAM services and click on your username(Stiles in my case) and then click Add permissions. Search for the S3FullAccess and Add this policy.
After updating the policy we need to login to the command line console. Use
aws configure — — profile Profilename
Choose a different region other than ap-south-1 as we cant create the S3 bucket in this region. Use
aws s3api help
to check more options on using this service.
For creating a bucket , first check
aws s3api create-bucket help
then run the following command
in my case i have given the bucket name as testb221 and give a access-control of public-read-write, we can also choose the option of only public-read in this command. So that the user can only view the contents of this bucket.
I have given a location constraint, you can explore more options by checking the help command.
We will now copy our content from the our system to the s3 bucket. Use
aws s3 help
command to check the options for copying , removing, showing list etc. these operations onto a local file.
Here I have use the cp command for copying the file and then giving the path about the location of file to the s3://bucketname/ and also I have set the acl list to the public-read file.
After uploading the object to the bucket we will create the CDN services for uploading these objects to all the nearby edge locations. Use
aws cloudfront help
to check different options provided by these services.
Now for creating a distribution use
aws cloudfront create-distribution help
to check different options provided by the servces.
here I have given the bucket name to the — — origin-domain-name option and the img file(in the bucket to share on the website) to the — default-root-object option.
The cloudfront services will provide us a unique domain name to acces thee object from the nearby edge locations. And we can use this link in our website to avoid the time latency.
I have updated this url in my aws instance.
Now start the services of the webserver using
systemctl start httpd
and adjust the width and height of the image accordingly.
The final output will be like this.