How CloudFront Works , Pricing ,Accessing and many more .

As I promised in the last Blog I will Explain How CloudFront works with regional edge caches, Locations and IP address ranges of CloudFront edge servers and access CloudFront & CloudFront pricing.

How CloudFront delivers content:

CloudFront works together with your website or application and speeds up the delivery of your content. This section explains how CloudFront serves your content when viewers request it.

Amazon CloudFront is a powerful content delivery network (CDN) service that accelerates the delivery of your web content to users across the globe. Here's a quick look at how CloudFront works.

How CloudFront delivers content to your users:

After you configure CloudFront to deliver your content, here’s what happens when users request your objects:

  1. A user accesses your website or application and sends a request for an object, such as an image file or an HTML file.

    We can example as any website(amazon, Flipkart...)

  2. DNS routes the request to the CloudFront POP (edge location) that can best serve the request—typically the nearest CloudFront POP in terms of latency—and routes the request to that edge location.

  3. CloudFront checks its cache for the requested object. If the object is in the cache, CloudFront returns it to the user. If the object is not in the cache, CloudFront does the following:

    1. CloudFront compares the request with the specifications in your distribution and forwards the request to your origin server for the corresponding object—for example, to your Amazon S3 bucket or your HTTP server.

    2. The origin server sends the object back to the edge location.

    3. As soon as the first byte arrives from the origin, CloudFront begins to forward the object to the user. CloudFront also adds the object to the cache for the next time someone requests it.

      Example:

      Let's say you have a website hosted on an S3 bucket, and you want to use CloudFront to deliver the static content of your website. Here are the steps:

  1. Create an S3 Bucket:

    • Upload your static files (HTML, CSS, JavaScript, images) to an S3 bucket.
  2. Create a CloudFront Distribution:

    • In the AWS Management Console, navigate to the CloudFront service.

    • Create a new distribution and configure the settings.

    • Specify the S3 bucket as the origin server.

  3. Distribution Deployment:

    • CloudFront will assign a domain name (e.g., d12345abcde.cloudfront.net) to your distribution.

    • Once the distribution is deployed, users can access your content using this CloudFront domain.

  4. Content Delivery:

    • When a user requests a resource from your website (e.g., an image), the request is directed to the nearest CloudFront edge location.
  5. Caching:

    • If the requested content is in the cache and is still valid, CloudFront serves it directly from the edge location, reducing latency.
  6. Origin Server Interaction:

    • If the content is not in the cache or has expired, CloudFront retrieves the content from the S3 bucket (origin server) and caches it for subsequent requests.

By using CloudFront, you improve the performance and reduce the load on your origin server, providing a faster and more reliable experience for your users.

How CloudFront works with regional edge caches:

Amazon CloudFront uses a global network of edge locations and regional edge caches to efficiently deliver content.

Regional edge caches store frequently accessed content at a broader geographical scale, reducing the load on origin servers and improving latency by serving content closer to users.

If the content is not in the regional cache, CloudFront falls back to fetch it from the origin server, caching it at both the regional and edge levels for subsequent requests.

This multi-tiered caching approach enhances the overall performance of content delivery for a global audience.

The Following Diagram Explains how requests and responses flow through CloudFront edge locations and regional edge caches.

Locations and IP address ranges of CloudFront edge servers:

Amazon CloudFront has a large number of edge locations worldwide, and the IP address ranges for these edge servers can change over time. It's not recommended to hardcode IP addresses for CloudFront, as AWS can dynamically add or remove edge locations. Instead, it's advised to use CloudFront domain names for your resources.

For a list of the locations of CloudFront edge servers, see the Amazon CloudFront Global Edge Network page.

Amazon Web Services (AWS) publishes its current IP address ranges in JSON format. To view the current ranges, download ip-ranges.json.

To find the IP address ranges that are associated with CloudFront edge servers, search ip-ranges.json for the following string:

"region": "GLOBAL", "service": "CloudFront"

Accessing CloudFront:

You can access Amazon CloudFront in the following ways:

Amazon CloudFront can be accessed and managed in several ways. Here are some common methods:

  1. AWS Management Console:

    • The AWS Management Console provides a web-based interface for managing CloudFront distributions. You can configure settings, create new distributions, and monitor performance through the console.
  2. AWS Command Line Interface (CLI):

    • The AWS CLI allows you to interact with CloudFront using commands in the terminal or command prompt. This is useful for scripting, automation, and bulk operations.

        # Example AWS CLI command to list CloudFront distributions
        aws cloudfront list-distributions
      
  3. AWS SDKs:

    • AWS provides Software Development Kits (SDKs) for various programming languages, such as Python, Java, JavaScript, and others. You can use these SDKs to integrate CloudFront functionality into your applications.
  4. CloudFront API:

    • The CloudFront API allows you to programmatically interact with CloudFront. This can be done using HTTP requests, and it's suitable for custom integration or automation.
  5. AWS CloudFormation:

    • AWS CloudFormation enables you to define CloudFront configurations as code using templates. This allows you to provision and manage CloudFront distributions alongside other AWS resources in a declarative manner.
  6. AWS Terraform Provider:

    • If you are using HashiCorp Terraform for infrastructure as code, there is an AWS provider that allows you to manage CloudFront distributions and related resources.
  7. Third-Party Tools:

    • Some third-party tools and platforms provide integrations with CloudFront for specific use cases. These tools might offer additional features or a different user experience for managing and optimizing content delivery.
  8. AWS SDK for Browser (JavaScript):

    • For browser-based applications, you can use the AWS SDK for JavaScript in the browser to interact with CloudFront directly from client-side code.

When accessing CloudFront, you will need appropriate AWS credentials (access key and secret key) to authenticate your requests, whether you are using the AWS Management Console, CLI, SDKs, or API. Additionally, permissions for CloudFront operations should be configured through AWS Identity and Access Management (IAM).

CloudFront pricing:

Amazon CloudFront is designed so you don’t have to pay any up-front fees or commit to how much content you'll have.

AWS provides two usage reports for CloudFront: a billing report and a report that summarizes usage activity.

The Above Diagram Explains the list and summarizes the charges to use CloudFront.

Amazon CloudFront pricing includes charges for data transfer out to end-users, request distribution, and optional features like invalidation requests, Field-Level Encryption, Lambda@Edge, Real-Time Logs, and additional services. Pricing is tiered, and there is a separate cost for regional data transfer. AWS offers a limited amount of CloudFront usage for free within the AWS Free Tier.

Example:

If you deliver 100 GB of data to users and make 1 million requests, you will incur charges based on these usage levels. For specific pricing details, refer to the official AWS CloudFront Pricing page.

Additional Information :

Your monthly bill from AWS allocates your usage and dollar amounts by AWS service and function.

The Above Diagram explains the charges that are illustrated in the previous graphic.

Charge for storage in an Amazon S3 bucket:

You pay normal Amazon S3 storage charges to store objects in your bucket. The charges appear in the Amazon S3 portion of your AWS statement.

Charge for serving objects from edge locations:

You incur CloudFront charges when CloudFront responds to requests for your objects. The charges include data transfer for WebSocket or gRPC data from server to client. The CloudFront charges appear in the CloudFront portion of your AWS statement as region -DataTransfer-Out-Bytes

Charge for submitting data:

You incur CloudFront charges when users transfer data to your origin or edge function, which includes DELETE, OPTIONS, PATCH, POST, and PUT requests. The charges include data transfer for WebSocket or gRPC data from client to server. The CloudFront charges appear in the CloudFront portion of your AWS statement as a region -DataTransfer-Out-OBytes.

Conclusion:

Amazon CloudFront empowers businesses to deliver content globally with speed and efficiency. Understanding how CloudFront works, managing costs through effective pricing strategies, and accessing it through various methods are key steps toward optimizing your content delivery infrastructure.

0
Subscribe to my newsletter

Read articles from Srikanth Vaddeneni directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Srikanth Vaddeneni
Srikanth Vaddeneni

Proficient in a variety of DevOps technologies, including AWS, Linux, Python, Shell Scripting, Docker, Terraform, and Computer Networking. I have a strong ability to troubleshoot issues.