Bobcares

How to setup AWS CloudFront and how it delivers content

by | Mar 21, 2021

Wondering how to setup AWS CloudFront? We can help you.

CloudFront retrieves data from the Amazon S3 bucket and distributes it to multiple datacenter locations. The data delivers through edge locations.

When we request data, the nearest edge location routes, resulting in the lowest latency, low network traffic, fast access to data, etc.

At Bobcares we assist our customers with several AWS queries as part of our AWS Support Services for AWS users, and online service providers.

Today, let us discuss how to setup AWS CloudFront

 

How AWS CloudFront Delivers the Content

Moving ahead, let us see how AWS does content delivery.

Step1: The user accesses a website and requests an object to download. For example, an image.
Step2: DNS routes this request to the nearest CloudFront edge location to serve the user request.
Step3: There, CloudFront checks its cache for the requested files. If found, returns it to the user otherwise does the following:

  • Initially, it compares the request with the specifications and forwards it to the applicable origin server for the corresponding file type.
  • The origin servers send the files back to the CloudFront edge location.
  • As soon as the first byte arrives from the origin, CloudFront forwards it to the user and adds the files to the cache in the edge location for the next time.

Step4: The object is now in an edge cache for 24 hours or so in file headers.

  • CloudFront forwards the next request for the object to the user’s origin to check the edge location version is updated or not.
  • If the edge location version is updated, then CloudFront delivers it to the user.
  • If the edge location version is not updated, then origin sends the latest version to CloudFront. CloudFront delivers the object to the user and stores the latest version in the cache at that edge location.

 

Features of CloudFront

  • Fast: The broad network results in lowering latency, high data transfer rates, and low network traffic.
  • Simple: It is easy to use.
  • Can use with other AWS Services: We can easily integrate it with other AWS services, like Amazon S3, Amazon EC2.
  • Cost-effective: We pay only for the content that we deliver through the network.
  • Elastic: We need not worry about maintenance
  • Reliable: Its edge locations will automatically re-route the end-users to the next nearest location if required.
  • Global: It uses a global network of edge locations located in most of the regions.

 

How to Setup AWS CloudFront

Now let us see how our Support Techs setup AWS CloudFront using the following steps.

Step1: Sign in to the AWS management console using https://console.aws.amazon.com/
Step2: Upload Amazon S3 and choose every permission public.
Step3: Create a CloudFront Web Distribution using the following steps:

  1. Open CloudFront console via https://console.aws.amazon.com/cloudfront/
  2. Click the Get Started button in the web section of ‘Select a delivery method for our content page’.
  3. Create Distribution page opens. Choose the Amazon S3 bucket in the Origin Domain Name and leave the rest as default.
  4. Then we can see a default Cache Behavior Settings page. Keep the values as default and move to the next page.
  5. A Distribution settings page opens. Fill in the requirements and click the Create Distribution button.
  6. The Status column changes from In Progress to Deployed. Enable the distribution.

Wait for around 15 minutes for the domain name to be available in the Distributions list.

  • Test the Links

Once done, CloudFront knows the location of the Amazon S3 server and the user knows the domain name associated with the distribution.

However, we can create a link to Amazon S3 bucket content with that domain name and have CloudFront serve it. This saves a lot of time.

Following are the steps to link an object:

Step1: Copy the following HTML code to a new file and write the domain-name that CloudFront assigned to the distribution in the place of the domain name. Write a file name of the Amazon S3 bucket in the place of object-name.

<html>
<head>CloudFront Testing link</head>
<body>
<p>My Cludfront.</p>
<p><img src = “http://domain-name/object-name” alt = “test image”/>
</body>
</html>

Step2: Save the text in a file with .html extension.
Step3: Then open the web page in a browser to see if it is working correctly. If not, then crosscheck the settings.

 

How to resolve HTTP 504 (Gateway Timeout) errors from CloudFront

Recently we had a customer who came across the error:

Amazon CloudFront distribution is returning an HTTP 504 (Gateway Timeout) error.

In order to troubleshoot HTTP 504 errors, we check the configurations on our firewall, security groups, and the origin server.

If we use a custom origin and can connect directly to the origin, but are getting 504 errors from CloudFront, then we increase the distribution’s origin response timeout.

By default, CloudFront allows the origin connection to open for 30 seconds. However, if we take more than 30 seconds to process and return a response, CloudFront returns an HTTP 504 error.

To optimize performance, the connection time between CloudFront and the origin should be kept as short as possible.

Our Support Techs recommend keeping the origin response timeout value as low as possible.

In order to do that, follow the given steps:

  1. Open the CloudFront console and then select the distribution.
  2. Choose the Origins and Origin Groups tab and then select the origin.
  3. Then select, Edit.
  4. Update the Origin Response Timeout value.
  5. Choose Yes and then Edit.

If we use persistent connections between CloudFront and the origin, we make sure that the origin keep-alive timeout value is equal to or greater than the origin response timeout.

[Need assistance with the setup? We are available 24*7]

 

Conclusion

In short, CloudFront retrieves data from the Amazon S3 bucket and distributes it to multiple datacenter locations. Today, we saw how our Support Techs setup AWS CloudFront.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF