Task 6
We perform following tasks in AWSCLI
1. webserver configured on EC2 instance.
2. Document root (/var/www/html) made persistent by mounting on EBS Block device.
3. Static objects used in code 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 cloud Front URL on the webapp code for security and low latency.
Launch Instance
To launch instance ,we require some information like ami, instance-type, subnet-id, security-group etc...
We use following command to launch our new instance
Aws ec2 run-instance –instance-type t2.micro –key-name cli_task --image-id ami-0e306788ff2473ccb --security-group-ids sg-07a5ad83c4754b1cb
Start instance
To start instance we use this command
aws ec2 start-instances --instance-ids i-04c88ae574db5551d
Create EBS Volume
For storing purpose we need to creat a volue here we creat a volume of EBS volume of size 1 gb
Aws ec2 creat-volume –availability-zone ap-south-1a --volume-type gp2 --size 1
Attach EBS volume to instance
Now we attach our volume to over instance
Aws ec2 attach-volume –instance-id i-04c88ae574db5551d --device xvdb --volume-id vol-0751c44590a8086d8
To use volume first od\f all we have to do
· Partition of EBS volume
· Format the EBS volume
· Mount to directory
Partition
The command used for partition is fdisk /dev/xvdb
Format
Formatting is must importiant thinge we can formate by
mkfs.ext4 /dev/xvdb1
Mount
mount /dev/xvdb1 /var/www/html/
Create S3 bucket
aws s3api creat-bucket --bucket task6bucket --creat-bucket-configuration LocationConstraint=ap-south-1
Upload file in S3 bucket
We can uplod our local file to s3 by following command
aws s3 cp C:\Users\ASUS\Downloads\takimg.jpg s3://task6bucket
Install httpd
To use web server we need to install appachi httpd software
yum install httpd –y
After installing we start httpd service by a lunix command
Service httpd start
For creation our web page first configure a file in /var/www/html/ dir
Creating a cloud front
To creat a cloudfront we use
aws cloudfront create-distribution --origin-domain-name task6bucket.s3.amazonaws.com
Our clint can access our web page by searchin in URL
httpd://<IP address>/<File name>