How AWS CloudFront works

0

I have an application deployed on AWS EC2 instance. This application is using AWS SDK to access AWS S3 bucket to store or retrieve audio files. Following is the diagram

Enter image description here

Now in order to improve performance I want to use AWS CloudFront to cache the audio files. Now with CloudFront put in place, do I need to change my application to point to CloudFront instead of pointing to AWS S3 bucket? Or my application still can point to AWS S3? If still can point to S3 bucket, then how CloudFront works in this situation? What the whole process looks like?

Enter image description here

Guojun
asked a month ago213 views
5 Answers
3

You can keep your application pointing to the S3 bucket. CloudFront caches S3 content globally and delivers it to users from the nearest edge location. No changes to your application are needed; it can still connect to S3 directly. CloudFront handles caching and optimization transparently, reducing latency and improving performance.

check this links for better understanding:- https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html#cf-features

profile picture
answered a month ago
  • Hi Kranthi putti

    Thank you for your prompt response.

    Then in terms of Origin configuration at CloudFront, I need to configure two Origins: 1. One Origin points to S3 Bucket, 2. another Origin points to my application deployed on EC2 instance? Or I only need to configure one Origin which points to my application deployed on EC2 instance? Because my situation is that the audio files are stored in S3 bucket. However the static app files, such as HTML, Javascript, CSS, images, will be on EC2 instances. I want CloudFront to cache and distribute both of audio files and app static files. So in this case, how to configure Origin server in CloudFront?

    Regarding the integration between my application and S3 bucket, I will be using VPC Endpoint.so that the traffic will be flowing via Amazon network. This should be okay right, not affect CloudFront right?

1

Hi Guojun,

Please look at below steps to resolve your issue:

  1. Request Flow: When a user requests an audio file through your application, the request is initially directed to CloudFront.

2.CloudFront Cache Check: CloudFront checks its cache to see if the requested audio file is already stored there. If the file is in the cache and hasn't expired, CloudFront serves the file directly to the user from its cache, providing faster access.

  1. Cache Miss: If the requested file isn't in CloudFront's cache (a cache miss), CloudFront forwards the request to the S3 bucket to retrieve the file.

  2. File Retrieval from S3: S3 retrieves the requested audio file and sends it back to CloudFront.

  3. Caching in Cloud Front: CloudFront caches the file it received from S3 before delivering it to the user. This means that subsequent requests for the same file can be served directly from CloudFront's cache, further improving performance.

  4. Delivery to User: CloudFront delivers the audio file to the user's device, completing the request.

Please go through the below cloud front documentation link you will get more info:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

answered a month ago
  • Thanks a lot for sharing it. From application prospective, my application will still connect to S3 using SDK to store and retrieve audio files, or I need to change my application configuration to point to CloudFront?

  • Hi Guojon,

    • From the application's perspective, you don't need to change the configuration to point directly to CloudFront.
    • Your application can continue to use the AWS SDK to store and retrieve audio files from the S3 bucket as it currently does.
    • CloudFront will sit between your application and the S3 bucket transparently, improving performance without requiring any changes to your application code or configuration.
    • your application interacts with S3 through the SDK just as before, and CloudFront handles caching and delivery of the audio files on behalf of S3.
    • This setup allows you to leverage CloudFront's caching capabilities to enhance performance without requiring any modifications to your application logic.
  • Hi Pandurangaswamy

    Thank you for your prompt response.

    Then in terms of Origin server configuration at CloudFront, DO I need to configure two Origins: 1. One Origin points to S3 Bucket, 2. another Origin points to my application deployed on EC2 instance? Or I only need to configure one Origin which points to my application deployed on EC2 instance? My situation is that the audio files are stored in S3 bucket (accessed via my application). However the static app files, such as HTML, Javascript, CSS, images, will be on EC2 instances. I want CloudFront to cache and distribute both of audio files and app static files. So in this case, how to configure Origin server in CloudFront?

1

Hi,

This CloudFront whitepaper is very specific to media streaming: https://docs.aws.amazon.com/pdfs/whitepapers/latest/amazon-cloudfront-media/amazon-cloudfront-media.pdf

Give it a deep read to find the optimal solution for your use case.

Best,

Didier

profile pictureAWS
EXPERT
answered a month ago
profile picture
EXPERT
GK
reviewed a month ago
  • Thank you, Didier.

0

With AWS CloudFront, you can indeed improve the performance of your application by caching content closer to your users. In your scenario, where you have an application deployed on an AWS EC2 instance accessing audio files from an S3 bucket using the AWS SDK, you can integrate CloudFront without needing to change your application's code to point directly to CloudFront.

Here's how it works:

Integration with CloudFront: You configure CloudFront to serve as a content distribution network (CDN) for your S3 bucket. This means CloudFront will cache copies of your audio files in edge locations around the world. Origin Configuration: You specify your S3 bucket as the origin for CloudFront. This means CloudFront will fetch content from your S3 bucket and cache it in its edge locations.

answered a month ago
0

Just want to confirm if below is correct traffic flow

This is without CloudFront. Below is the traffic flow for

  1. user retrieves audio file list from application.
  2. user plays audio file from application.

Enter image description here Enter image description here

When introducing CloudFront, below is the traffic flow. I know there are other solutions for streaming the audio file directly from S3 bucket. But this is our solution and we already confirmed this solution. Just that I want to confirm if this traffic flow is correct. Enter image description here

Enter image description here

Guojun
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions