How Amazon CloudFront helps to implement fast Content Delivery Network

How Amazon CloudFront helps to implement fast Content Delivery Network

Since you all know about the biggest cloud in the market i.e., Amazon Web Services (AWS) and how companies using AWS to run their business. If not, I’ve also written one blog on that also, you can go and read that also.

So, today we will be going to discuss what could be the problems which business might face and how AWS or I would say cloud can solve those. And we’ll also demonstrate using the service provided by AWS i.e., CloudFront also known as CDN (Content Delivery Network).

But first we will see a case study to understand the problem well and after that we will go forward with the practical.

PBS Case Study

PBS(Public Broadcasting Service) is a private, non-profit corporation that offers all Americans a wide variety of educational and entertainment programming through television and online content. PBS programming is delivered to individual communities through its nearly 360 member stations throughout the United States. In addition to television programs, PBS also provides content through mobile applications and several websites, including PBS.org, PSKID.org, PBS Video. Founded in 1969, PBS has transformed itself from a solely broadcast organization to a multi-platform leader that serves Americans through television, mobile TV, the Web, interactive whiteboards in the classroom and more.

“As with all the AWS services we leverage, using Amazon CloudFront is so simple and reliable that the team doesn’t have to think about it. It all just works, freeing us to focus on building cool applications.”


The Challenge

Drew Engelson is Chief Architect and Senior Director of Platform Development for PBS Interactive, the department responsible for PBS’ Internet and mobile presence. Initially, Engelson and his team employed a content delivery network that did not fully meet their needs for delivering streamed media files. This led to the periodic failure of streamed videos to start playing, as well as the chance that some video streams would freeze and not restart.

Because there was no method of measuring performance degradation through PBS’ existing content delivery network, Engelson and his team had difficulty identifying the source of these video streaming issues. To improve the system and prevent these types of issues, PBS Interactive implemented a monitoring tool that could also be used to test other content delivery networks, including Amazon Web Services (AWS). Already familiar with AWS, the PBS Interactive team was already using Amazon Elastic Compute Cloud (EC2) and Amazon Simple Storage Service (Amazon S3).

Why Amazon Web Services

After monitoring multiple CDNs for a few weeks, PBS Interactive found that CloudFront had a significantly lower error rate than the incumbent CDN. As a result, they migrated the majority of PBS videos to Amazon S3 storage and delivered them via Amazon CloudFront. PBS Interactive completed the migration of its content into Amazon S3 within a matter of weeks and subsequently began delivering that content via Amazon CloudFront.

Since the migration, PBS Interactive says it has experienced fifty percent fewer errors in its video streaming performance. The department also conducts testing more quickly with the help of Amazon CloudFront’s invalidation request feature and by analyzing CloudFront logfiles. This feature improves PBS Interactive’s testing by rapidly removing bad files and quickly refreshing its cache.

Engelson believes that “Amazon CloudFront fits well with the other AWS services used by PBS. The team members have enjoyed their conversations with the AWS team as they have migrated to Amazon CloudFront, and they were pleased when the Amazon CloudFront invalidation feature was released shortly after they needed that feature.”

The Benefits
  • Delivers more than 1 petabyte of video content each month via CloudFront
  • Improves user experience for viewers
  • Reduced errors in video-streaming performance by 50%

I hope after going through with the Case-Study you got the know about the service which AWS provides i.e., CloudFront. CloudFront not only helps PBS for their live streaming there are many more businesses which uses CloudFront for their Profits. Many of you might know Amazon Prime Video, it also uses the CloudFront service for live streaming of one the most famous NFL Thursday Night Football Games in more than 200 countries.

Now, buckle up your belts because this hands-on will make you feel bore but this will give you a lot of information about the CloudFront and how it works. So without wasting a single more second

Let’s Begin……

These are some steps which we will be going to perform

  • Create IAM User.
  • Configure Profile for AWS CLI
  •  Create a Security Group.
  •  Launch a EC2 Instance using Security Group and Key Pair.
  • Create a EBS Volume of 1GB.
  • Attach the above create volume to the Instance created.
  • Configure a Webserver on EC2 Instance.
  • Mount /var/www/html to the attached EBS volume (Block Device) to make the location persistent.
  • Create S3 Bucket and place the static object in the bucket and make it publicly accessible.
  • Create and setup Content Delivery Network using CloudFront using the origin domain of S3 bucket.
  • Use the Cloud Front Domain in the code instead of S3 domain name for security and low latency during access.

I’ll be performing most of the above steps using AWS CLI, you can also use AWS Management Console.

Step 1: Create IAM User

  • Login to AWS Management Console using root account.
  • Search for IAM Service.
No alt text provided for this image
  • Click on users and then Add User.
No alt text provided for this image
  • Enter Username and choose the Access Type, I’m choosing Programmatic access.
No alt text provided for this image
  • Click on Next Permission and then click to Attach existing policies and select AdministratorAccess.
No alt text provided for this image
  • Then click on Next: Tags and add tag if you want to. I’m simply skipping this.
  • Now Review your user and Click on Create User.
No alt text provided for this image
  • That’s it you have successfully created an IAM user and you got the Access Key and Secret access key and you can also save the credential file in csv format.
No alt text provided for this image

Step 2: Configure the AWS Command Line Interface (CLI) following the below steps.

  • We will setup the AWS Access Key Id.
  • We will setup the AWS Secret Access Key.
  •  We will setup the Default Region Name.
  •  We will setup the Default Output Format.

# aws configure

No alt text provided for this image

Step 3: Under this step we will be creating one Security Group with name as “CloudFrontSG” and allowing all the ingress traffic means open for entire world.

# aws ec2 create-security-group --description Security_Group_for_CloudFront --group-name CloudFrontSG

No alt text provided for this image

Now the Security Group has been created and you can check that on AWS Management Console.

No alt text provided for this image

But as of now no Inbound Rule has been created for this Security Group. Now we will be defining one rule for our security group.

# aws ec2 authorize-security-group-ingress --group-id sg-0183f1b7098b3adb0 --protocol all --cidr 0.0.0.0/0

No alt text provided for this image
No alt text provided for this image

Step 4: Since we have pre created Key-Pair and Security Group with us, we can move ahead with the creation of an EC2 instance.

# aws ec2 run-instances --image-id ami-0a9d27a9f4f5c0efc --security-group-ids sg-0183f1b7098b3adb0 --instance-type t2.micro --subnet-id subnet-3a5c5452 --key-name awsclass2020key

No alt text provided for this image
No alt text provided for this image

Step 5: Now we will create an EBS Volume of size 1GB to store our code persistent and we will create the EBS Volume in the same region where we have launched our EC2 instance.

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

No alt text provided for this image
No alt text provided for this image

Step 7: Now we have to attach our EBS volume to EC2 instance which we had just created in previous step.

# aws ec2 attach-volume --instance-id i-052f45aa96c08c8ea --volume-id vol-070c82c246c04ce74 --device /dev/xvdh

No alt text provided for this image

Now we have both the EC2 instance and EBS Volume of 1GB attached to it.

Step 8: Now SSH Login to EC2 instance using Public IP of your EC2-instance and the Key Pair with the help of software called Putty.

No alt text provided for this image
No alt text provided for this image

Step 9: Now we need to create a partition from the disk, format that partitions and mount it to a folder in the instance.

Check the available partitions in the disk

# fdisk -l

No alt text provided for this image

First we need to format the disk attacked to instance

# mkfs.ext4 /dev/xvdh

No alt text provided for this image

Now it’s time to start creating partitions

# fdisk /dev/xvdh

Select p to see the details of available partitions

# p

Select n to create a new partition

# n

Select p to create a primary partition

# p

Select 1 to create a single partition

# 1

Starting of the first sector, starting from 2048 as default

# press Enter

Ending of the sector, ending at 2097151 by default (entire size)

# press Enter

No alt text provided for this image

Step 10: Now install httpd server using the following command.

# yum install httpd

No alt text provided for this image

You can start services of httpd using command

# systemctl start httpd

No alt text provided for this image

Step 11: After server setup now mount the formatted created partition to document root (/var/www/html) using command

# mount /dev/xvdh1 /var/www/html

No alt text provided for this image

Step 12: Now to store objects like images, videos, file we need S3 bucket. For creating S3 bucket run command in AWS CLI.

# aws s3api create-bucket --bucket frontex --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1

No alt text provided for this image
No alt text provided for this image

And we have put 1 image in our S3 bucket

No alt text provided for this image

Step 13: Since we have one image in S3 bucket create one cloud front and use that cloud front domain in code. For creating cloud front domain write below command.

# aws cloudfront create-distribution --origin-name frontex.s3.ap-south-1.amazonaws.com

No alt text provided for this image
No alt text provided for this image

Step 14: Now the final step is to create code in the document root /var/www/html named ad index.html

# index.html

<html>

<head>

         <title>CloudFront Example</title>

</head>

<body>

         <center>

         <h1>Amazon AWS Logo</h1>

         <img src=”https://d20scb88wo8eam.cloudfront.net/aws-logo.png” height =”400” width=”400”>

              </center>

</body>

</html>

No alt text provided for this image

Now access the website using public domain or public IP of EC2 instance.

No alt text provided for this image


Himangini Khanna

Associate Software Engineer | Cyber Security

4 年

Well Explained.

要查看或添加评论,请登录

Gaurav Dargan的更多文章

社区洞察

其他会员也浏览了