Any of the services which we are getting in the Market are all based on some use-cases, some challenges and in order to solve these challenges these services has been created. Cloud Front is one of them, that has been created to solve the problem of latency in accessing the data from a distant server. For this, we will learn about different concepts like CDN, Edge Location, etc. Now we will go through each and every term used in creating a setup for cloud Front with an example altogether. We know that AWS has its Data Center at different places all over the world, One of the places in Mumbai also. It is designed in such a way that clients will not face any latency problem like if a client is near California so he can use that data center and can work easily with its resources, also if a person is from India he may use the Datacenter in Mumbai. But is it really working for such regions like Delhi, Rajasthan, etc(some places in India)? It's true that it is not possible to set up the Data Centers so for this there is a solution for this, which is the concept of CDN through Edge Locations.
Now if we create an Instance and try to access the Instance
Now we will set up a web server in our Instance and then create a web page in it. Here we used SSH we can also use PuTTY in place of SSH
To install anything in our OS or Instance we need to move to the root user.
Update the Index Page
For accessing our web server we need to start the service of the webserver
On accessing the web page through the IP, we will get the output but will take some time
Here we get the output :
Hence, we can see that this is taking time to get the output from the Availability Zone. So there is a solution to this problem, i.e., Edge Location based on CDN (Content Delivery Network).
What is Edge Location?
An edge location is where end-users access services located at AWS, the cloud computing division of US-headquartered Amazon. They are located in most of the major cities around the world and are specifically used by CloudFront (CDN) to distribute content to end-users to reduce latency.
In simple words, the locations where we can access the services at a single time and the end-user can use these services for multiple times so that the user need not to send the packets to Mumbai every time when they access the services.
As the Latency problem arises due to large regional distances. This above network designed in such a way that we are setting up a small data center at Delhi is called Edge Location. Here also we will try to set up such a network that will only transfer the required data from the Availability zone. Now we can also define the term CDN (Content Delivery Network), it is the network through which we transfer the required data or services from the Availability zone to some specific Edge locations in order to reduce the Latency problem and provide the clients an easy and fast access to resources.
There is a program behind Edge Location, through edge location it will take the request to the Availability Zone and the Availability Zone will transfer the required data or services to the Edge location. Now, this Edge Location will store a copy of this Accessed data in its local storage, so that when the client go to this edge location, and request for accessing the same data or services they can access it from the local copy.
Edge Location is also known as Proxy Setup. By default, the time for local copy is 1 day, but we can also change this default time. From where we are accessing the data, that is known as the origin.
Here we are going to access the data from the Web server, this means the webserver is the origin. Amazon sets such a system that it provides a single URL and when any client type this URL, this URL will automatically identify which edge location has requested and it automatically allocates the nearest edge location to it or nearest Availability Zone to it. This intelligence is provided through a service called DNS(Domain Name System). This system provides Fault Tolerance.
This setup is known as Distribution and it provides CDN.
We will complete this setup step by step:
Step 1 Go to Cloud Front, a service of Network & Content Delivery
Step 2. For Creating Distribution, click on Create Distribution
Step 3. Fill all the details to create the distribution, In origin name, we will add the DNS name of the webserver
Step 4. We can check all the details of the Distribution here :
Step 5 Access the Web Server through the DNS that CloudFront Provided
Here, we saw Viewer Protocol and Origin Protocol.
The main difference between these two protocols is The viewer protocol works in between the client and edge location (through https).
The Origin Protocol works in between edge and origin(here our origin is EC2 instance) through HTTP.
So, we have successfully accessed the webserver through the CloudFront DNS URL. But if we think in such a way that what happens if the developer change some layout or something on the web page, then do these changes will be accessed at the client-side at the same time?
The Answer is No. It's true that we can’t access the changes at the same time because the TTL time or the Updation time of Edge location is 1 day(by default) so the updates will be accessed after one day only. For this also we have an option of Invalidation.
We want whatever changes we make at the origin, that will be updated all over the edge locations, and the cache should also be removed.
Invalidation is the concept in which the objects can remove the CloudFront edge cache data. We use (*) to delete everything. After applying the Invalidation for everything, the Distribution edge needs to forward the request for the data and access the data from the origin.
For creating an Invalidation,
Step 1 we go the created distribution and see the current Distribution settings and click on Create Invalidation
Step 2 Create Invalidation
Step 3 Details about Invalidation can be accessed from Details
Step 4 Now, we will make some changes in the code of web page
Step 5 Try to access the Web Page now through the DNS URL of Cloud Front.
We have successfully accessed the updated web page at the same time with the help of the Invalidation Concept. This is how AWS provides a CDNaas (Content Delivery Network as a Service), CloudFront.
Just like CloudFront, we have a lot of services that are provided by AWS to solve many problems in real-time and they have many efficient and interesting use cases.