ARTH TASK 6

Devanshu Singh
3 min readNov 15, 2020

--

By Team ARTH2020.1.3

Question

1. Store static data (Eg: Images) in an S3 bucket and increase the global availability using AWS CloudFront

2. Launch an AWS EC2 instance (Preferably Linux based), and add an additional EBS storage for data availability even after the EC2 instance is terminated. Setup the Apache Webserver and mount the html directory to make the data stored persistent.

3. Launch an HTML page displaying the static object previously uploaded in the S3 bucket through CloudFront Domain URL

Solution

1. Creating an S3 bucket and setting bucket ACL to public-read

a) aws s3api create-bucket — bucket devanshu-test-bucket — region ap-south-1 — createbucket-configuration LocationConstraint=ap-south-1

b) aws s3api put-bucket-acl — acl public-read — bucket devanshu-test-bucket

Figure 1: S3 bucket

2. Uploading static object to S3 bucket and setting object permission to public-read to all

a) aws s3api put-object — bucket devanshu-test-bucket — key sample-image.jpg -body D:\wp-1584712839268.jpg

b) aws s3api put-object-acl — bucket devanshu-test-bucket — key sample-image.jpg — grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers

3. Creating CloudFront with created S3 bucket as the origin

aws cloudfront create-distribution — origin-domain-name my-akshaya-testbucket.s3.amazonaws.com

Figure 2: CloudFront Distribution

4. Creating EBS volume of 1 GiB

aws ec2 create-volume — volume-type gp2 — size 1 — availability-zone ap-south-1a

Figure 3: EBS Volume

5. Launching EC2 instance in same AZ as the EBS volume, with user data script

aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro -count 1 — subnet-id subnet-ff757197 — security-group-ids sg-058c56a541fc9b7da -key-name arth_hadoop_key — user-data file://userdata_input.txt — tag-specifications “ResourceType=instance,Tags=[{Key=Name,Value=test_cli_os}]”

Figure 4: Userdata script to be run when EC2 instance is launched

6. Attaching EBS volume to the EC2 instance, creating a partition, formatting and mounting the partition on html directory using script_file

aws ec2 attach-volume — instance-id i-0a4ba6899ddf362ce — volume-id vol09497655cc782dec9 — device /dev/xvdf

Figure 5: Attaching EBS volume to EC2 instance
Figure 6: Before executing script_file — I
Figure 7: Before executing script_file — II
Figure 8: Contents of script file written through a user-data file in the AWS CLI
Figure 9: After execution of script file — I
Figure 10: After execution of script file — II
Figure 11: After execution of script file — III
Figure 12: Final website output

--

--

No responses yet