Creating Cloud Front Service Or Distribution In AWS

Introduction

Amazon cloud front is basically a web service that helps you to speed up distribution of your static and dynamic web content such as .html,.css,.js and image files etc.

Cloud front basically delivers your content through a worldwide network of data centers which is used to call edge locations.

The advantage of cloud front is that users can easily navigate the URL and see the image.

Cloud front speeds up the distribution of your content by routing each user request to the edge location that can basically serve your content.

Typically, this cloud front edge server provides the fastest delivery to the viewer.

Another advantage is to get increased reliability and availability because it creates the copy of your files in multiple edge locations around the world.

Let's see how to create the Cloud Front Distribution

  • Sign up with http://aws.amazon.com.
  • Now the first thing you have to do is upload your content in the S3 Bucket to access and distribute in cloud front distribution.
  • Cloud front can distribute almost any type of objects like text, images, and videos.
  • Also, you can create multiple buckets there is no limit for how much data you can store in Amazon S3.
  • By default, Amazon S3 bucket objects are private so you must give permission to read or write objects in it. So that it allows anyone to access the objects in your Amazon S3 bucket using cloud front URLs. You must grant read permission to all the objects.
  • Create S3 Bucket.
  • Sign in to https://console.aws.amazon.com/s3/.
  • In Amazon S3 console, choose to create a bucket.
  • In the Create Bucket dialog, enter bucket name.

    AWS

    AWS
  • Click on Next, as of now there is no need to set properties.
  • Set permissions – Select from drop-down give – Give public read access to this bucket.
  • Select another drop-down set to manage system permission – Grant Amazon S3 log delivery group write access to this bucket.

    AWS
  • Click Next and at last Create bucket.
  • Once the bucket is created successfully you can upload your files/content to it.

    AWS

  • Now, upload a sample image file into your bucket.

    AWS

  • On the Upload – Select Files, choose Add Files Upload and choose the files that you want to upload, let's say - Sample jpg image and give public access grant permission to it.
  • Enable public read privileges for each object that you upload to your Amazon S3 Bucket.
  • Choose Next to set permissions.
  • In the Manage public permission drop-down list, grant public read access to this object.
  • Choose Next.
  • Set any properties  that you want for the object, such as encryption or tagging and choose Next.
  • Choose Upload.
  • Once the upload is completed you can navigate to the item by using the URL. 
    AWS

Create a Cloud Front Web Distribution

  • So now create cloud front console.
  • Open cloud front service and click on Create Distribution.
  • After that Select Delivery method for your content in the web section and choose Get Started.

    AWS
  • In the Create Distribution page, under Origin Settings, choose your S3 bucket which you have created earlier.
  • So, For Origin ID, Origin Path, Restrict Bucket Access, and Origin Custom Headers accepts the default value as it is.

    AWS

So, Under Default Cache Behavior Settings

  • Accepts the default values.
  • You forward all requests that use the cloud front URL for your distribution.
  • http://abc.cloudfront.net/image.jpg) to the Amazon S3 bucket that you specified in the above steps.
  • Allow end users to use either HTTP or HTTPS to access your objects in S3 bucket.
  • Respond to your request for all your objects.
  • Cache your objects whenever it's required at cloud front edge locations for 24 hours.
  • Allow everyone to see your content.
  • Not automatically compress your content.
  • You can just forward only default request headers to your origin and not cache objects based on values in headers.
  • Exclude cookies and query string parameters.

    AWS

Now Under distribution settings

  • Price class
    Select a price class that corresponds to a maximum price that you want to pay for your cloud front service. Cloud front basically serves your objects from edge locations in all cloud Front regions.
  • AWS WAF Web ACL
    Helps to allow or block HTTP and HTTPS requests based on criteria that you specify, choose the web ACL to associate with this distribution.
  • CName
    If you want to change the domain name and give your own then specify one or more domains that you want to use for URLs for objects instead of the domain name that cloud front assigns when you create your distribution.
  • SSL certificate
    Accept the default certificate, Default Cloud Front Certificate.
  • Default Root object
    This is mainly used for when you want cloud front to request from your origin. So, use it when a viewer requests the root URL of your distribution (http://viraljain.com/) instead of an object in your distribution.
  • Logging
    You can store log files in Amazon S3 bucket if you want cloud front to log the information about each request for your object. So you need to select "ON" and specify the bucket and an optional prefix for the names of the log files.
  • Cookie Logging
    Amazon S3 as the origin of your objects so we recommend that you select "OFF" for the value of cookie Logging.
  • The Comments box is optional
    Enter any comments if you want to save any comments with the distribution.
  • Distribution state
    This is a very important configuration for your cloud front, you need to select "Enabled" if you want your cloud front processing requests as soon as the distribution is created or Select "Disabled" if you do not want cloud front to begin processing requests after the distribution is created.

    AWS
  • Now, click on Create Distribution.
  • So, once your cloud Front has created your distribution, status for your distribution will change from in progress to deployed.

Test Your link

Copy the following HTML into a new file:

  • Replace <domain name> with the domain name that CloudFront assigned to your distribution.
  • Replace <object name> with the name of a file in your Amazon S3 bucket.
    1. <html>  
    2.   
    3. <head>My CloudFront Test</head>  
    4.   
    5. <body>  
    6.     <p>My text content goes here.</p>  
    7.     <p><img src="http://domain name/object name" alt="my test image" /> </body>  
    8.   
    9. </html>  

For example, if your domain name was abc.cloudfront.net and your object was image.jpg, the URL for the link would be:

http://abc.cloudfront.net/image.jpg.

  • Save the text in a file and give filename extension as .html.
  • Now, open your web page in a browser to ensure that you can see your content.

    AWS

     AWS

Hope you like my article. This is how we can create cloud front distribution service.


Similar Articles