Task 5- AWS CSA

Peeyush Yadav
5 min readAug 25, 2021

Task description:

  • Create High Availability Architecture with AWS CLI.
  • The architecture includes-
  1. A web server configured on EC2 instance
  2. Document Root (/var/www/html) made persistent by mounting on EBS Block Device.
  3. Static objects used in code such as pictures stored in S3.
  4. Setting up Content Delivery Network using CLoudFront and using the origin domain as S3 bucket.
  5. Finally, place the CloudFront URL on the web app code for security and low latency.

Requisites:

  • The pre-requisites of this task include an AWS CLI software already on your system and login to your AWS account using the special token key and password combination given to you at the beginning of setting up the account.

Step 1: Launching an instance

Run the following command:

aws ec2 run-instance — image-id <your assigned image id> — instance-type t2.micro — subnet-id <your subnet id> — security-group-ids <your desired security group id> — key-name <key-pair name to be used> — count 1

Step 2: Creating Volume:

  • Run the following command

aws ec2 create-volume — availability-zone <your availability zone> — volume-type gp2 — size 10

Step 3: Attaching the volume.

  • Run the following command

aws ec2 attach-volume-id <volume id of the volume to be attached> — instance-id <instance id of the instance to which the volume should be attached to> — device /dev/sdf

Step 4: Creating Partition

  • Run the following command.
  • ssh -l ec2-user <your ec2 instance public address> -i <key-pair name>.pem sudo fdisk /dev/xvdf

Step 5: Formatting Partition

  • Run the following command

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem sudo mkfs.ext4 /dev/xvdf

Step 6: Mounting a directory

  • Run the following command.

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem sudo mount /dev/xvdf /var/www/html

Step 7: Installing apache webserver

  • Run the following command.

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem sudo yum install httpd -y

Step 8: Start httpd and check the status

  • Run the following command.

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem sudo systemctl start httpd

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem sudo systemctl status httpd

Step 9: Connect to the instance via the CLI

  • Run the following command.

ssh -l ec2-user <your instance public address> -i <key-pair name>.pem

Now, we will create an S3 bucket and insert an object into it.

Step 10: Create an S3 bucket

  • Run the following command.

aws s3api create-bucket — bucket <bucket name> — region <availability region> — create-bucket-configuration Location=<availability region>

Time to make the bucket available to the entire zone, by making it public

Step 11: Make the bucket public

  • Run the following command.

aws s3api put-bucket-acl — acl public -read — bucket <bucket name>

Step 12: Putting the object in the bucket.

  • Run the following command.

aws s3api put-object — bucket <bucket-name> — key <give a directory name for the bucket>/<image name to be stored in the bucket> -body <location of the image from your local storage>

Since we made the bucket public, it necessarily doesn't mean that its content would also be public altogether. Thus, we now make the picture to be public. This would enable the data in the bucket to be read by the webserver, rather than just download and read.

Step 13: Making the object public

  • Run the following command.

aws s3api put-object-acl — bucket <bucket name> — key <directory name>/<onject name stored in the bucket> — grant-read uri=http://acs.amazonaws.com/global/AllUsers

Step 14: Creating CloudFront Distribution

  • Run the following command.

aws cloudfront create-distribution — origin-domain-name your s3 bucket domain> — default-root-object <path to the object from the bucket>

Now we can the status of the CloudFront Distributions and check for deployment over them.

Now we can see that we have successfully deployed the CloudFront distributions.

We can now successfully download the object (image this case)

Step 15: Deleting the S3 bucket object

  • Run the following command.

aws s3api delete-object — bucket <bucket name> — key <path of the object in the bucket>

Step 16: Deleting the S3 bucket

  • Run the following command.

aws s3api delete-bucket — bucket <bucket name> — region <availability zone of the bucket>

That’s it! The task is completed

Hope you had a great read. Thanks.

I duly thank Mr. Vimal Daga and his team for their guidance and team throughout this process of learning.

Looking forward to learning even further and share opportunities for the same.

Adios.

#awscloud #awscli #aws #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeudcation #awsbylw

--

--