AWS CloudFront

AWS CloudFront


3 min read

CloudFront provides valuable solution for content delivery networks (CDNs), offering numerous benefits for global content distribution. s a

CDN Overview:

  • Problem: When content (like an image) is stored in a central location, users accessing it from distant locations experience latency due to data traveling through multiple routers.

  • Solution: CDNs like CloudFront create local copies of content (caching) in edge locations closer to users, reducing latency.

S3 Disadvantages for Static Websites:

  • Cost: S3 can be costly for frequent uploads and downloads.

  • Latency: Accessing S3 buckets from distant regions can increase latency.

  • Security: S3 can be less secure if not properly configured, potentially allowing unauthorized access.

CDN Benefits (Using CloudFront):

  • Caching: CloudFront caches content in edge locations, reducing the need for frequent requests to the origin server (like S3).

  • Cost-Effectiveness: By reducing data transfer costs, CloudFront can be more cost-effective than accessing content directly from S3.

  • Improved Performance: Users experience faster load times as content is served from nearby edge locations.

  • Security: CloudFront provides additional security features, such as access control and encryption, improving overall security.

CloudFront Example by Hosting Static website :

  1. Create a bucket in AWS console by selecting create bucket.

  2. Enter the bucket name and select the location for bucket.

  3. Select the object ownership and keep the block all public access as checked.

    Then, create the bucket.

  4. Bucket will be displayed here,

  5. Open the bucket and add the static file to host.

  6. Go to properties and scroll down to enable static website hosting.

  7. When you try to access the bucket, you will get Forbidden.

  8. Now we need to add CloudFront distribution to the bucket.

    Search CloudFront in the console.

  9. Select create CloudFront Distribution.

  10. Choose the origin domain and select the origin access to Origin Access Control setting and create new OAC or select the existing.

In this, I have selected origin acces control setting which enables makes only cloudFront to access the s3. In this I have to manullay update the policy for the bucket. You can choose Legacy access identitites which has option of automatic policy updation.

  1. Select the Viewer Options

Viewer protocl policy - Determines if the users can access the contents using http or https.

Allowed HTTP methods - Specify which method that cloudFront need to redirect the request to S3.

Cache Key and Origin requests - Specifies how cloudFront caches ans retrives the content.

  1. Choose the WAF and change the settings if needed.

    Web Application Firewall(WAF) allow to manage and configure security rules.

    SSL Certificate - Attach the SSL certificates if any.

    Price Class - Choose the locations where the contents need to be cached.

    Default root object - Specifies the default file to be served when visitor access the URL.

  2. We have Created the cloudFront Distribution. Now we need to attach the policy to S3 bucket.

  3. Select the copy policy in header section and go to s3 bucket permissions.

  4. Scroll down and select edit policy in policy section and paste the copied policy & save it.

  5. Now wait for few minutes for the cloudFront to deploy in all locations and copy the distribution domain name when deployed.

  6. Open the distribution domain name in browser , You will be able to see the contents in static site.

    Finally, we have created a static site hosting using s3 bucket and integrated them with CDN (CloudFront).

    Conclusion: In summary, CloudFront is a powerful tool for optimizing content delivery, reducing latency, and improving the performance and security of static websites hosted on S3 or other origin servers.

Did you find this article valuable?

Support Gopinath J by becoming a sponsor. Any amount is appreciated!