{"id":10803,"date":"2024-05-19T04:22:27","date_gmt":"2024-05-19T01:22:27","guid":{"rendered":"https:\/\/sunucun.com.tr\/bilgi\/?post_type=dt_articles&#038;p=10803"},"modified":"2026-11-12T13:52:50","modified_gmt":"2026-11-12T10:52:50","slug":"what-is-amazon-cloudfront-and-how-to-use-it","status":"publish","type":"post","link":"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/","title":{"rendered":"What Is Amazon CloudFront and How Do You Use It? AWS CDN Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Amazon CloudFront<\/strong> is AWS&#8217;s content delivery network (CDN). It caches your website&#8217;s images, CSS\/JS files, videos and even API responses at <strong>edge locations<\/strong> around the world, so visitors get content from the point closest to them. Pages load faster and the load on your origin server drops. In this article we explain how CloudFront works, its core concepts and its cache settings, based on the AWS documentation.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_91 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#How_Does_CloudFront_Work\" >How Does CloudFront Work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Core_Concepts\" >Core Concepts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Cache_Duration_TTL_and_Cache-Control\" >Cache Duration: TTL and Cache-Control<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Step_by_Step_A_Static_Site_with_S3_CloudFront\" >Step by Step: A Static Site with S3 + CloudFront<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Security_and_Extra_Features\" >Security and Extra Features<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Pricing\" >Pricing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/sunucun.com.tr\/blog\/what-is-amazon-cloudfront-and-how-to-use-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_Does_CloudFront_Work\"><\/span>How Does CloudFront Work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A visitor requests an address such as <code>cdn.yoursite.com\/logo.png<\/code>; DNS routes the request to the nearest CloudFront edge location.<\/li>\n<li>If the file is in that edge location&#8217;s cache and hasn&#8217;t expired, it is served from there.<\/li>\n<li>If not, CloudFront fetches the file from the origin (an S3 bucket, EC2 server, load balancer or any web server outside AWS), sends it to the visitor and stores it in the cache.<\/li>\n<li>When the file expires, CloudFront asks the origin whether it has changed; if not, the origin returns <code>304 Not Modified<\/code> and the cached copy keeps being used.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Core_Concepts\"><\/span>Core Concepts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Distribution:<\/strong> The configuration you create in CloudFront; it gives you a domain such as <code>d111111abcdef8.cloudfront.net<\/code>. You can attach your own domain with a CNAME and an SSL certificate.<\/li>\n<li><strong>Origin:<\/strong> Where the content actually lives: an S3 bucket, EC2, an Elastic Load Balancer or your own server.<\/li>\n<li><strong>Cache behavior:<\/strong> Lets you define different caching and routing rules by path pattern (for example <code>\/images\/*<\/code>, <code>\/api\/*<\/code>).<\/li>\n<li><strong>Cache policy:<\/strong> Sets the cache duration (TTL) and which headers, cookies and query strings are included in the cache key.<\/li>\n<li><strong>Invalidation:<\/strong> Removes a file from the cache before it expires.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Cache_Duration_TTL_and_Cache-Control\"><\/span>Cache Duration: TTL and Cache-Control<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">According to the AWS documentation, if you don&#8217;t use a cache policy the default TTL is 24 hours. You manage cache duration in two ways: with the Minimum, Default and Maximum TTL values in the cache behavior, or with the <code>Cache-Control<\/code> header sent by the origin.<\/p>\n\n\n\n<div class=\"snc-table-wrap\"><table>\n<thead><tr><th>Header sent by the origin<\/th><th>How long CloudFront caches it (with Minimum TTL = 0)<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>Cache-Control: max-age=3600<\/code><\/td><td>The lesser of max-age and Maximum TTL<\/td><\/tr>\n<tr><td><code>max-age<\/code> and <code>s-maxage<\/code> together<\/td><td>The lesser of s-maxage and Maximum TTL; browsers follow max-age<\/td><\/tr>\n<tr><td>No caching header<\/td><td>The Default TTL<\/td><\/tr>\n<tr><td><code>no-cache<\/code>, <code>no-store<\/code> or <code>private<\/code><\/td><td>Not cached (if Minimum TTL is greater than 0, cached for the Minimum TTL)<\/td><\/tr>\n<\/tbody><\/table><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>s-maxage<\/code> you can set different durations for the CDN and the browser. For example, <code>Cache-Control: max-age=300, s-maxage=86400<\/code> caches for 5 minutes in the browser and 1 day in CloudFront. CloudFront also supports the <code>stale-while-revalidate<\/code> and <code>stale-if-error<\/code> directives, so it can keep serving the old copy when the origin is temporarily down.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_by_Step_A_Static_Site_with_S3_CloudFront\"><\/span>Step by Step: A Static Site with S3 + CloudFront<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Upload your files to an S3 bucket. The bucket doesn&#8217;t need to be public.<\/li>\n<li>In the CloudFront console, choose <strong>Create distribution<\/strong>, select the S3 bucket as the origin and use Origin Access Control (OAC) so that only CloudFront can access the bucket.<\/li>\n<li>Set the viewer protocol to <strong>Redirect HTTP to HTTPS<\/strong> and add a certificate from AWS Certificate Manager for your own domain.<\/li>\n<li>Choose a suitable cache policy and create the distribution.<\/li>\n<li>In your domain&#8217;s DNS, point a record such as <code>cdn<\/code> to the CloudFront domain.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To publish an updated file immediately, you can clear it from the cache:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>aws cloudfront create-invalidation \\\n  --distribution-id E1234567890ABC \\\n  --paths \"\/css\/*\" \"\/index.html\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For frequently changing files, adding a version to the file name (for example <code>style.v42.css<\/code>) is a more reliable and usually cheaper approach than invalidations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Security_and_Extra_Features\"><\/span>Security and Extra Features<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HTTPS with free SSL certificates from AWS Certificate Manager<\/li>\n<li>Network-layer DDoS protection with AWS Shield Standard, and optional application-layer rules with AWS WAF<\/li>\n<li>Signed URLs and cookies to serve content only to authorized users<\/li>\n<li>CloudFront Functions and Lambda@Edge to run small pieces of code at the edge, such as redirects or adding headers<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Pricing\"><\/span>Pricing<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Besides the pay-as-you-go model (based on data transfer and number of requests), CloudFront offers flat-rate monthly plans, including a free plan. Because prices and quotas vary by region and plan, check the current details on AWS&#8217;s CloudFront pricing page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For services commonly used as CloudFront origins, see our articles on <a href=\"https:\/\/sunucun.com.tr\/blog\/aws-s3-simple-storage-service-why\/\">Amazon S3<\/a> and <a href=\"https:\/\/sunucun.com.tr\/blog\/aws-ec2-elastic-compute-cloud-2\/\">Amazon EC2<\/a>, and for monitoring, <a href=\"https:\/\/sunucun.com.tr\/blog\/aws-cloudwatch-why\/\">Amazon CloudWatch<\/a>. If you are looking for a fast origin server to sit behind your CDN, take a look at our <a href=\"https:\/\/sunucun.com.tr\/en\/vds-server\">VDS server<\/a> options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Amazon CloudFront is a CDN that speeds up delivery by serving content from the edge location closest to the visitor and reduces the load on your origin. The right cache behaviors and TTLs, Cache-Control headers and OAC for S3 help you get the best performance and security from CloudFront.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Amazon CloudFront is AWS&#8217;s content delivery network (CDN). It caches your website&#8217;s images, CSS\/JS files, videos and even API responses at edge locations around the world, so visitors get content from the point closest to them. Pages load faster and the load on your origin server drops. In this article we explain how CloudFront works,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":10706,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1519],"tags":[1527],"class_list":["post-10803","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sanal-sunucu","tag-teknoloji"],"_links":{"self":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/10803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/comments?post=10803"}],"version-history":[{"count":1,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/10803\/revisions"}],"predecessor-version":[{"id":19840,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/posts\/10803\/revisions\/19840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/media\/10706"}],"wp:attachment":[{"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/media?parent=10803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/categories?post=10803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunucun.com.tr\/blog\/wp-json\/wp\/v2\/tags?post=10803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}