Setting up Fast & Secure Globally scaled Content Delivery Network with high availability using AWS…

Setting up Fast & Secure Globally scaled Content Delivery Network with high availability using AWS…

January 1, 20235 min readSri VishnuvardhanSri Vishnuvardhan

In this article, we are going to see about what is the Content Delivery Network, why we need them, what are its use cases and then finally we are going to set up our own Content Delivery Network with Fast, Secure and high availability using one of the most powerful services provided by AWS namely Cloudfront.

Content Delivery Network

A Content Delivery Network (CDN) is a globally distributed network of web servers whose purpose is to provide faster content delivery. The content is replicated and stored throughout the CDN so the user can access the data that is stored at a location that is geographically closest to the user.

This is different and more efficient than the traditional method of storing content on just one, central server. A client accesses a copy of the data near to the client, as opposed to all clients accessing the same central server, in order to avoid bottlenecks near that server.

source: Globaldots

High content loading speed ==positive User Experience

CDN Architecture model

The above figure clearly illustrates the typical CDN model. When a user requests the content, for the first time it will send to Content Provider, then Content Provider will send their copy of the document known as Source to CDN and that copy is stored as digital information which is created, licensed and ready for distribution to an End User. If the User requests the content again, he will receive the content from CDN only which is located nearer to the geographical location of the user, not from Content Provider. We can reduce latency and ensure high availability.

Benefits of CDN over Traditional method

  • CDN enables global reach
  • 100% percent availability
  • Your reliability and response times get a huge boost
  • Decrease server load
  • Analytics

Use-Cases of CDN

  • Optimized file delivery for emerging startups
  • Fast and secure E-Commerce
  • Netflix-grade video streaming
  • Software Distribution, Game Delivery and IoT OTA

CloudFront

credits: whizlabs

Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment. CloudFront uses Origins from S3 for setting up its Content Delivery Network.

Cloudfront uses Edge locations to store the data cache. Currently, AWS now spans 77 Availability Zones within 24 geographic regions around the world and has announced plans for 18 more Availability Zones and 6 more AWS Regions in Australia, India, Indonesia, Japan, Spain, and Switzerland.

AWS uses DNS to find the nearest data centers for storing the caches. Data comes from Origin to Edge location and Edge location to our PC.

Practicals

Now I am going to show you how to setup your Custom Own Content Delivery Network for your content which includes images, videos, etc. Before going into this, please refer to my previous blog where I explained how to launch the instances, security groups, key-pairs, EBS volumes by using AWS Command Line Interface from scratch.

Click here to view my previous blog for getting started with AWS CLI if you not known already about AWS CLI.

Pre-requisites

  • AWS account
  • AWS instance
  • EBS volume

For saving time, I already launched one Amazon instance and one EBS volume sized 10GB and attached to its instance.

Steps

  • Installing HTTPD server
  • Making its document root persistent
  • S3
  • Deployed it to CloudFront

Installing HTTPD server

Since the package manager “YUM” is already installed in Amazon Linux 2, so run the following commands for configuration of HTTPD server in that instance.

yum install httpd -y

Then we have to start the service.

yum start httpd 

We have to enable the service. So that we need not start the service again and again after every reboot.

yum enable httpd

Making its document root persistent

Since the OS in Amazon 2 Linux is RHEL 8, so the document root of HTTPD server is /var/www/httpd. The document root is the location where the HTTPD server reads and deployed it into the web page. We have to make that document root persistent in order to secure the data from being lost due to OS crash etc.

For that, you have to ready with the previously created one EBS volume and done with the partition. Then run the following command.

mount /var/www/html /partition

Simple Storage Service

Since the Origin for CloudFront is S3, we have to setup S3 so that we can get the Origin Domain name for CloudFront. In S3, the folders are said to be buckets and files are said to be Objects.

First step is to create a bucket by using the following command syntax.

aws s3 mb s3://bucketname

The second step is to move/copy the objects to the buckets by using following command syntax.

aws s3 mv object-location s3://bucketname

By default, Public access for S3 buckets is blocked. We have to release the access by running the following command syntax in your Windows Command Prompt.

aws s3api put-public-access-block --bucket bucketname --public-access-block-configuration “BlockPublicAcls=false, IgnorePublicAcls=false, BlockPublicPolicy=false, RestrictPublicBuckets=false” 
aws s3api put-object-acl --acl "public-read" --bucket "bucketname"  --key objectname

We had completed the S3 setup, the HTML code of the webpage is shown below.

CloudFront

source: stackflow

Since Origin S3 setup is over, now we have to setup the CloudFront by creating one distribution using Origin Domain Name from S3 and Object name as Default Root Object.

We have to run the following command to create a distribution

aws cloudfront create-distribution --origin-domain-name vishnu1234.s3.amazonaws.com --default-root-object Scam-1992.jpg

After creating the distribution, CloudFront will give one domain address, we have to copy that domain address to that HTML code and it will replace the S3 domain address.

Finally our Output will be…

Thank you friends for your patience to read this article. Kindly please let me know about your feedbacks so that I can improve my writings. I even didn't need any claps or likes too. Just need feedback for improving me to give engaged insightful contents to you all. That’s it. Have a good day.
Sri Vishnuvardhan

Written by

Sri Vishnuvardhan

Building production-grade geospatial platforms that combine GIS, remote sensing, cloud infrastructure, AI, and platform engineering to transform spatial data into scalable, real-world intelligence.

Enjoyed this article?

Subscribe to get notified when new articles on DevOps, Cloud, and platform engineering are published.

You'll receive a welcome email with a confirmation link. No spam — unsubscribe anytime.

Have a project in mind?

I work on cloud-native platforms, DevOps automation, and geospatial intelligence systems. Let's talk.

Get in touch
Setting up Fast & Secure Globally scaled Content Delivery Network with high availability using AWS… — Sri Vishnuvardhan A