Deploying webserver by creating a High Availability Architecture 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.

Step 1: Launch an instance in AWS

aws ec2 run-instances --image-id <value> --instance-type <value> --key-name <value> --subnet-id <value> --count <value> --security-group-ids <value> --tag-specifications <value>

Step 2: Create volume

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

Step 3: Attach volume to the instance that is created

aws ec2 attach-volume --device <value>  --instance-id <value> --volume-id <value>

By using the command fdisk -l you can view the details of the sector that you have created

Step 4:install httpd

Enable httpd serviced by using the command systemctl enable httpd

Step 5:Create partition

Step 6:Format

Step 7: Mount the partition

Using the command df -h , we can verify that our partition has been mounted on the /var/www/html folder

Step 8: Create S3 bucket

aws s3 mb s3://mybucket --region ap-south-1
You can verify through GUI that a bucket has been created

Step 9: Upload static images in s3 bucket

aws s3 cp <source> <target> [--options]
Command to upload an image nature.jpg into the bucket created in the previous step
Through GUI, you can see that the image has been uploaded

Setting Permissions

For an object that you’ve already stored in Amazon S3, you can run this command to update its ACL for public read access:

aws s3api put-object-acl --bucket DOC-EXAMPLE-BUCKET --key exampleobject --acl public-read

Step 10: Create html webpages

Object URL:

webpage.html file created in /var/www/html folder

Step 11: Create CDN

General command:

aws cloudfront create-distribution --origin-domain-name <value> --default-root-object <value>
We can see in GUI that the distribution has been deployed

Step 12:Place CloudFront URL on webapp code

This URL can be placed in our html code instead of the ObjectURL written previously.

The reason to perform this step is to provide a better user experience by ensuring security and low latency.


Thanks for reading

-Vijaya Madhuri T A