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 a S3 bucket.
- Finally, place the Cloud Front URL on the web app code for security and low latency.
STEPS:-
1.First of all We have to launch Ec2-instance by using Cli for webserver configuration.
2. We have to login aws through cli by using ‘aws configure’.
3. Creating Key Pair Using Aws Cli:-
for creating key pair by using command is “ aws ec2 create-key-pair — key-name myawscli” here the key name is “Awscloudf”
4. Creating a Security Group Using Aws Cli:-
To create security group by using command “aws ec2 create-security-group — description allowall — group-name awscli vpc-id vpc-bc56b0d7”
In security group we have to add rule to access the ssh (port 22)and http (port 80)
To access ssh command is “aws ec2 authorize-security-group-ingress — group-id sg-06a79fbe0804f5a65— protocol tcp — port 22 — cidr 0.0.0.0/0
To access http command is “aws ec2 authorize-security-group-ingress — group-id sg-06a79fbe0804f5a65— protocol tcp — port 80 — cidr 0.0.0.0/0”
5. Launched a instance by using above created key pair and security group:-
To launched Ec2 instance by using cli(command line interface) command is :-aws ec2 run-instances — image-id ami-04b1ddd35fd71475a — instance-type t2.micro — count 1 — subnet-id subnet-285f2364 — security-group-ids sg-06a79fbe0804f5a65 — key-name Awscloudf — tag-specifications ResourceType=instance,Tags=[{key=Name,Value=CF}]
Here ec2-instance is launched then configure the webserver go to command prompt of ec2 instance then using command “sudo -su root “ to switch the root user and then we have to http(webserver) service command is “ yum install httpd”
After that start the webserver command is “systemctl start httpd”. Here, webserver store all the code by default path “/var/www/html” it is store in ‘/’ drive if by chance os get corrupted the whole data will lose so that we have to store all data of this folder in external volume(EBS) here we mount the volume in “/var/www/html” and s3 for storing static data.
6. To create Ebs volume and attach the instance then mount it to /var/www/html folder
- Creating EBS volume 1 Gb:-
The command is to create an ebs volume “aws ec2 create-volume — availability-zone ap-south-1b — size 1”
- Attach the Ebs volume to instance
the command “aws ec2 attach-volume — device /dev/sdf — instance-id i-079fe330a2ec3802e — volume-id vol-04d348325dc61c37a”
Then, we have go to aws command prompt to check volume attached by the command ‘fdisk -l’, After that we have to create partition of that volume command is ‘fdisk /dev/xvdf’ and format the partition command is “mkfs.ext4 /dev/xvdf”.And then th mount the /var/www/html folder to that volume.
7. To create s3 bucket
The command is “aws s3api create-bucket — bucket wbserver21 — region ap-south-1 — create-bucket-configuration LocationConstraint=ap-south-1”
- to store data in s3
command is “aws s3 cp C:\Users\HP\Downloads\aws.jpg s3://web1234server/ — acl public-read”
8. Copy the URL of image and put in a new tab to see the image upload in the s3 bucket.
9. Then we have to write a html code to access the image file where the actual URL is hidden.
10. To create a cloudfront distribution :
For creating cloudfront distribution we use command :aws cloudfront create-distribution — origin-domain-name wbserver21s3.amazonaws.com”
you want to access the image file in s3 by domain name url is http://d29hhckp9ix10o.cloudfront.net/aws.jpg
And update the html code by this url and the final output when cloudfront distribution url update
Thank you!!!