Amazon CloudFront
Developer Guide
Amazon CloudFront: Developer Guide
Copyright © Amazon Web Services, Inc. and/or its affiliates. All rights reserved.
Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon.
Table of Contents
What is Amazon CloudFront? ... 1
How you set up CloudFront to deliver content ... 1
Use cases ... 3
Accelerate static website content delivery ... 3
Serve video on demand or live streaming video ... 3
Encrypt specific fields throughout system processing ... 4
Customize at the edge ... 4
Serve private content by using Lambda@Edge customizations ... 4
How CloudFront delivers content ... 5
How CloudFront delivers content to your users ... 5
How CloudFront works with regional edge caches ... 6
Locations and IP address ranges of CloudFront edge servers ... 8
Use the CloudFront managed prefix list ... 8
Accessing CloudFront ... 8
How to get started with Amazon CloudFront ... 9
AWS Identity and Access Management ... 9
CloudFront pricing ... 9
Savings bundle ... 11
Choosing the price class for a CloudFront distribution ... 14
Setting up ... 16
Sign up for AWS ... 16
Access your account ... 16
Access the console ... 17
Access the API, AWS CLI, AWS Tools for Windows PowerShell, or the AWS SDKs ... 17
Create an IAM user ... 17
Set up the AWS Command Line Interface or AWS Tools for Windows PowerShell ... 19
Download an AWS SDK ... 19
Getting started ... 20
Getting started with a simple distribution ... 20
Prerequisites ... 20
Step 1: Upload your content to Amazon S3 and grant object permissions ... 21
Step 2: Create a CloudFront distribution ... 22
Step 3: Access your content through CloudFront ... 22
Getting started with AWS for WordPress ... 23
Prerequisites ... 24
Step 1: Install the plugin ... 26
Step 2: Configure and use CloudFront with the plugin ... 26
(Optional) Deactivate site acceleration ... 28
(Optional) Remove site acceleration and delete the CloudFront distribution ... 29
(Optional) Deactivate and remove the plugin ... 29
(Optional) Create a CloudFront distribution for Amazon Polly content ... 30
Troubleshooting ... 30
Getting started with a secure static website ... 32
Solution overview ... 33
Deploying the solution ... 34
Working with distributions ... 37
Overview of distributions ... 37
Actions you can use with distributions ... 38
Required fields for creating and updating distributions ... 38
Creating, updating, and deleting distributions ... 40
Steps for creating a distribution ... 40
Creating a distribution ... 41
Values that you specify ... 42
Values that are displayed ... 65
Testing a distribution ... 66
Updating a distribution ... 66
Tagging a distribution ... 67
Deleting a distribution ... 69
Using different origins ... 70
Using Amazon S3 buckets for your origin ... 70
Using Amazon S3 buckets configured as website endpoints for your origin ... 71
Using a MediaStore container or a MediaPackage channel for your origin ... 71
Using Amazon EC2 or other custom origins ... 72
Using origin groups ... 72
Adding CloudFront when you have Amazon S3 content ... 73
Moving an Amazon S3 bucket to a different region ... 74
Using custom URLs ... 74
Adding an alternate domain name ... 75
Moving an alternate domain name to a different distribution ... 77
Removing an alternate domain name ... 81
Using wildcards in alternate domain names ... 82
Requirements for using alternate domain names ... 82
Restrictions on using alternate domain names ... 83
Using WebSockets ... 84
How the WebSocket protocol works ... 84
WebSocket requirements ... 85
Working with policies ... 86
Controlling the cache key ... 86
Creating cache policies ... 87
Understanding cache policies ... 90
Using the managed cache policies ... 94
Understanding the cache key ... 96
Controlling origin requests ... 98
Creating origin request policies ... 99
Understanding origin request policies ... 102
Using the managed origin request policies ... 104
Adding the CloudFront HTTP headers ... 105
Headers for determining the viewer’s device type ... 106
Headers for determining the viewer’s location ... 106
Other CloudFront headers ... 107
Adding response headers ... 107
Creating response headers policies ... 107
Using the managed response headers policies ... 112
Understanding response headers policies ... 115
Adding, removing, or replacing content ... 119
Adding and accessing content ... 119
Updating existing content ... 119
Updating existing files using versioned file names ... 120
Updating existing content using the same file names ... 120
Removing content so CloudFront won’t distribute it ... 121
Customizing file URLs ... 121
Using your own domain name (example.com) ... 121
Using a trailing slash (/) in URLs ... 122
Creating signed URLs for restricted content ... 122
Specifying a default root object ... 122
How to specify a default root object ... 122
How headers work with default root objects ... 123
How CloudFront works if you don’t define a root object ... 124
Invalidating files ... 125
Choosing between invalidating files and using versioned file names ... 125
Determining which files to invalidate ... 126
Specifying the files to invalidate ... 126
Invalidating files using the console ... 128
Invalidating files using the CloudFront API ... 130
Concurrent invalidation request maximum ... 131
Paying for file invalidation ... 131
Serving compressed files ... 131
Configuring CloudFront to compress objects ... 131
How CloudFront compression works ... 132
Notes about CloudFront compression ... 132
File types that CloudFront compresses ... 134
ETag header conversion ... 135
Generating custom error responses ... 135
Configuring error response behavior ... 136
Creating a custom error page for specific HTTP status codes ... 137
Storing objects and custom error pages in different locations ... 138
Changing response codes returned by CloudFront ... 138
Controlling how long CloudFront caches errors ... 139
Configuring secure access and restricting access to content ... 141
Using HTTPS with CloudFront ... 141
Requiring HTTPS between viewers and CloudFront ... 142
Requiring HTTPS to a custom origin ... 143
Requiring HTTPS to an Amazon S3 origin ... 145
Supported protocols and ciphers between viewers and CloudFront ... 146
Supported protocols and ciphers between CloudFront and the origin ... 150
Charges for HTTPS connections ... 151
Using alternate domain names and HTTPS ... 151
Choosing how CloudFront serves HTTPS requests ... 152
Requirements for using SSL/TLS certificates with CloudFront ... 154
Quotas on using SSL/TLS certificates with CloudFront (HTTPS between viewers and CloudFront only) ... 157
Configuring alternate domain names and HTTPS ... 158
Determining the size of the public key in an SSL/TLS RSA certificate ... 161
Increasing the quotas for SSL/TLS certificates ... 161
Rotating SSL/TLS certificates ... 162
Reverting from a custom SSL/TLS certificate to the default CloudFront certificate ... 163
Switching from a custom SSL/TLS certificate with dedicated IP addresses to SNI ... 164
Restricting content with signed URLs and signed cookies ... 164
Overview of serving private content ... 165
Task list for serving private content ... 166
Specifying signers ... 167
Choosing between signed URLs and signed cookies ... 173
Using signed URLs ... 174
Using signed cookies ... 187
Using Linux commands and OpenSSL for base64 encoding and encryption ... 201
Code examples for signed URLs ... 202
Restricting access to Amazon S3 content ... 221
Overview of OAI setup ... 221
Creating a CloudFront OAI and adding it to your distribution ... 222
Granting the OAI permission to read files in your Amazon S3 bucket ... 223
Using an OAI in Amazon S3 regions that support only signature version 4 authentication ... 226
Restricting access to Application Load Balancers ... 226
Configuring CloudFront to add a custom HTTP header to requests ... 227
Configuring an Application Load Balancer to only forward requests that contain a specific header ... 228
(Optional) Improve the security of this solution ... 232
Using AWS WAF to control access to your content ... 232
Geographically restricting content ... 233
Using CloudFront geographic restrictions ... 234
Using a third-party geolocation service ... 235
Using field-level encryption to help protect sensitive data ... 236
Overview of field-level encryption ... 238
Setting up field-level encryption ... 239
Decrypting data fields at your origin ... 242
Optimizing caching and availability ... 245
Caching with edge locations ... 245
Improving your cache hit ratio ... 245
Specifying how long CloudFront caches your objects ... 246
Using Origin Shield ... 246
Caching based on query string parameters ... 246
Caching based on cookie values ... 247
Caching based on request headers ... 247
Remove Accept-Encoding header when compression is not needed ... 248
Serving media content by using HTTP ... 248
Using Origin Shield ... 248
Use cases for Origin Shield ... 249
Choosing the AWS Region for Origin Shield ... 252
Enabling Origin Shield ... 253
Estimating Origin Shield costs ... 255
Origin Shield high availability ... 255
How Origin Shield interacts with other CloudFront features ... 255
Increasing availability with origin failover ... 256
Creating an origin group ... 257
Controlling origin timeouts and attempts ... 258
Use origin failover with Lambda@Edge functions ... 259
Use custom error pages with origin failover ... 259
Managing cache expiration ... 260
Using headers to control cache duration for individual objects ... 261
Specifying the amount of time that CloudFront caches objects ... 261
Adding headers to your objects using the Amazon S3 console ... 264
Caching and query string parameters ... 265
Console and API settings for query string forwarding and caching ... 266
Optimizing caching ... 266
Query string parameters and CloudFront standard logs (access logs) ... 267
Caching content based on cookies ... 267
Caching content based on request headers ... 269
Headers and distributions – overview ... 270
Selecting the headers to base caching on ... 271
Configuring CloudFront to respect CORS settings ... 271
Configuring caching based on the device type ... 272
Configuring caching based on the language of the viewer ... 272
Configuring caching based on the location of the viewer ... 272
Configuring caching based on the protocol of the request ... 272
Configuring caching for compressed files ... 272
How caching based on headers affects performance ... 273
How the case of headers and header values affects caching ... 273
Headers that CloudFront returns to the viewer ... 273
Troubleshooting ... 274
Troubleshooting distribution issues ... 274
CloudFront returns an InvalidViewerCertificate error when I try to add an alternate domain name ... 274
I can’t view the files in my distribution ... 275
Error message: Certificate: <certificate-id> is being used by CloudFront ... 276
Troubleshooting error responses from your origin ... 277
HTTP 400 status code (Bad Request) ... 277
HTTP 500 status code (Lambda execution error) ... 278
HTTP 502 status code (Bad Gateway) ... 278
HTTP 502 status code (Lambda validation error) ... 280
HTTP 503 status code (Lambda limit exceeded) ... 280
HTTP 503 status code (Service Unavailable) ... 281
HTTP 504 status code (Gateway Timeout) ... 281
Load testing CloudFront ... 284
Request and response behavior ... 286
Request and response behavior for Amazon S3 origins ... 286
How CloudFront processes HTTP and HTTPS requests ... 286
How CloudFront processes and forwards requests to your Amazon S3 origin ... 286
How CloudFront processes responses from your Amazon S3 origin ... 291
Request and response behavior for custom origins ... 292
How CloudFront processes and forwards requests to your custom origin ... 292
How CloudFront processes responses from your custom origin ... 302
Request and response behavior for origin groups ... 305
Adding custom headers to origin requests ... 306
Use cases for origin custom headers ... 306
Configuring CloudFront to add custom headers to origin requests ... 306
Custom headers that CloudFront can’t add to origin requests ... 307
Configuring CloudFront to forward the Authorization header ... 308
How range GETs are processed ... 308
Use range requests to cache large objects ... 309
How CloudFront processes HTTP 3xx status codes from your origin ... 309
How CloudFront processes and caches HTTP 4xx and 5xx status codes from your origin ... 309
How CloudFront processes errors when you have configured custom error pages ... 310
How CloudFront processes errors when you have not configured custom error pages ... 311
HTTP 4xx and 5xx status codes that CloudFront caches ... 313
Video on demand (VOD) and live streaming video ... 314
About streaming video: video on demand and live streaming ... 314
Delivering video on demand (VOD) ... 315
Configuring video on demand for Microsoft Smooth Streaming ... 315
Delivering live streaming video ... 317
Serving video using AWS Elemental MediaStore as the origin ... 317
Serving live video formatted with AWS Elemental MediaPackage ... 318
Customizing with edge functions ... 322
Choosing between CloudFront Functions and Lambda@Edge ... 322
Customizing with CloudFront Functions ... 324
Tutorial: Creating a simple function ... 324
Writing function code (programming model) ... 328
Managing functions ... 352
Monitoring functions ... 364
Customizing with Lambda@Edge ... 366
Get started creating and using Lambda@Edge functions ... 367
Setting IAM permissions and roles ... 377
Writing and creating functions ... 382
Adding triggers ... 385
Testing and debugging ... 390
CloudWatch metrics and logs ... 395
Deleting functions and replicas ... 396
Event structure ... 396
Working with requests and responses ... 407
Example functions ... 411
Restrictions on edge functions ... 437
Restrictions on all edge functions ... 437
Restrictions on CloudFront Functions ... 441
Restrictions on Lambda@Edge ... 441
Reports, metrics, and logs ... 444
AWS billing and usage reports for CloudFront ... 444
AWS billing report for CloudFront ... 444
AWS usage report for CloudFront ... 445
Interpreting your AWS bill and the AWS usage report for CloudFront ... 446
CloudFront console reports ... 449
CloudFront cache statistics reports ... 450
CloudFront popular objects report ... 454
CloudFront top referrers report ... 457
CloudFront usage reports ... 460
CloudFront viewers reports ... 464
Monitoring CloudFront with Amazon CloudWatch ... 472
Viewing CloudFront and Lambda@Edge metrics ... 472
Setting alarms ... 476
Downloading data ... 477
Getting metrics using the API ... 478
CloudFront logging ... 482
Logging requests ... 482
Logging service activity ... 483
Using standard logs (access logs) ... 483
Real-time logs ... 495
Capturing API requests with CloudTrail ... 507
Tracking configuration changes with AWS Config ... 512
Set up AWS Config with CloudFront ... 513
View CloudFront configuration history ... 513
Security ... 515
Data protection ... 515
Encryption in transit ... 516
Encryption at rest ... 517
Restrict access to content ... 517
Identity and Access Management (IAM) ... 518
Authentication ... 518
Access control ... 519
Overview of managing access ... 519
Using IAM policies for CloudFront ... 524
CloudFront API permissions reference ... 529
AWS managed policies ... 533
Logging and monitoring ... 536
Compliance validation ... 537
CloudFront compliance best practices ... 537
Resilience ... 538
CloudFront origin failover ... 538
Infrastructure security ... 538
Quotas ... 540
General quotas ... 540
General quotas on distributions ... 540
General quotas on policies ... 541
Quotas on CloudFront Functions ... 542
Quotas on Lambda@Edge ... 542
Quotas on SSL certificates ... 543
Quotas on invalidations ... 544
Quotas on key groups ... 544
Quotas on WebSocket connections ... 544
Quotas on field-level encryption ... 545
Quotas on cookies (legacy cache settings) ... 545
Quotas on query strings (legacy cache settings) ... 545
Quotas on headers ... 546
Related information ... 547
Additional Amazon CloudFront documentation ... 547
Getting support ... 547
CloudFront developer tools and SDKs ... 547
Tips from the Amazon Web Services blog ... 548
Document history ... 549
AWS glossary ... 554
How you set up CloudFront to deliver content
What is Amazon CloudFront?
Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a
worldwide network of data centers called edge locations. When a user requests content that you're serving with CloudFront, the request is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.
• If the content is already in the edge location with the lowest latency, CloudFront delivers it immediately.
• If the content is not in that edge location, CloudFront retrieves it from an origin that you've defined—
such as an Amazon S3 bucket, a MediaPackage channel, or an HTTP server (for example, a web server) that you have identified as the source for the definitive version of your content.
As an example, suppose that you're serving an image from a traditional web server, not from CloudFront.
For example, you might serve an image, sunsetphoto.png, using the URL http://example.com/
sunsetphoto.png.
Your users can easily navigate to this URL and see the image. But they probably don't know that their request is routed from one network to another—through the complex collection of interconnected networks that comprise the internet—until the image is found.
CloudFront speeds up the distribution of your content by routing each user request through the AWS backbone network to the edge location that can best serve your content. Typically, this is a CloudFront edge server that provides the fastest delivery to the viewer. Using the AWS network dramatically reduces the number of networks that your users' requests must pass through, which improves performance.
Users get lower latency—the time it takes to load the first byte of the file—and higher data transfer rates.
You also get increased reliability and availability because copies of your files (also known as objects) are now held (or cached) in multiple edge locations around the world.
Topics
• How you set up CloudFront to deliver content (p. 1)
• CloudFront use cases (p. 3)
• How CloudFront delivers content (p. 5)
• Locations and IP address ranges of CloudFront edge servers (p. 8)
• Accessing CloudFront (p. 8)
• How to get started with Amazon CloudFront (p. 9)
• AWS Identity and Access Management (p. 9)
• CloudFront pricing (p. 9)
How you set up CloudFront to deliver content
You create a CloudFront distribution to tell CloudFront where you want content to be delivered from, and the details about how to track and manage content delivery. Then CloudFront uses computers—
edge servers—that are close to your viewers to deliver that content quickly when someone wants to see it or use it.
How you configure CloudFront to deliver your content
1. You specify origin servers, like an Amazon S3 bucket or your own HTTP server, from which
CloudFront gets your files which will then be distributed from CloudFront edge locations all over the world.
An origin server stores the original, definitive version of your objects. If you're serving content over HTTP, your origin server is either an Amazon S3 bucket or an HTTP server, such as a web server. Your HTTP server can run on an Amazon Elastic Compute Cloud (Amazon EC2) instance or on a server that you manage; these servers are also known as custom origins.
2. You upload your files to your origin servers. Your files, also known as objects, typically include web pages, images, and media files, but can be anything that can be served over HTTP.
If you're using an Amazon S3 bucket as an origin server, you can make the objects in your bucket publicly readable, so that anyone who knows the CloudFront URLs for your objects can access them.
You also have the option of keeping objects private and controlling who accesses them. See Serving private content with signed URLs and signed cookies (p. 164).
3. You create a CloudFront distribution, which tells CloudFront which origin servers to get your files from when users request the files through your web site or application. At the same time, you specify details such as whether you want CloudFront to log all requests and whether you want the distribution to be enabled as soon as it's created.
Use cases
4. CloudFront assigns a domain name to your new distribution that you can see in the CloudFront console, or that is returned in the response to a programmatic request, for example, an API request.
If you like, you can add an alternate domain name to use instead.
5. CloudFront sends your distribution's configuration (but not your content) to all of its edge locations or points of presence (POPs)— collections of servers in geographically-dispersed data centers where CloudFront caches copies of your files.
As you develop your website or application, you use the domain name that CloudFront provides for your URLs. For example, if CloudFront returns d111111abcdef8.cloudfront.net as the domain name for your distribution, the URL for logo.jpg in your Amazon S3 bucket (or in the root directory on an HTTP server) is http://d111111abcdef8.cloudfront.net/logo.jpg.
Or you can set up CloudFront to use your own domain name with your distribution. In that case, the URL might be http://www.example.com/logo.jpg.
Optionally, you can configure your origin server to add headers to the files, to indicate how long you want the files to stay in the cache in CloudFront edge locations. By default, each file stays in an edge location for 24 hours before it expires. The minimum expiration time is 0 seconds; there isn't a maximum expiration time. For more information, see Managing how long content stays in the cache (expiration) (p. 260).
CloudFront use cases
Using CloudFront can help you accomplish a variety of goals. This section lists just a few, together with links to more information, to give you an idea of the possibilities.
Topics
• Accelerate static website content delivery (p. 3)
• Serve video on demand or live streaming video (p. 3)
• Encrypt specific fields throughout system processing (p. 4)
• Customize at the edge (p. 4)
• Serve private content by using Lambda@Edge customizations (p. 4)
Accelerate static website content delivery
CloudFront can speed up the delivery of your static content (for example, images, style sheets, JavaScript, and so on) to viewers across the globe. By using CloudFront, you can take advantage of the AWS backbone network and CloudFront edge servers to give your viewers a fast, safe, and reliable experience when they visit your website.
A simple approach for storing and delivering static content is to use an Amazon S3 bucket. Using S3 together with CloudFront has a number of advantages, including the option to use Origin Access Identity (OAI) to easily restrict access to your S3 content.
For more information about using S3 together with CloudFront, including a AWS CloudFormation template to help you get started quickly, see Amazon S3 + Amazon CloudFront: A Match Made in the Cloud.
Serve video on demand or live streaming video
CloudFront offers several options for streaming your media to global viewers—both pre-recorded files and live events.
• For video on demand (VOD) streaming, you can use CloudFront to stream in common formats such as MPEG DASH, Apple HLS, Microsoft Smooth Streaming, and CMAF, to any device.
• For broadcasting a live stream, you can cache media fragments at the edge, so that multiple requests for the manifest file that delivers the fragments in the right order can be combined, to reduce the load on your origin server.
For more information about how to deliver streaming content with CloudFront, see Video on demand and live streaming video with CloudFront (p. 314).
Encrypt specific fields throughout system processing
When you configure HTTPS with CloudFront, you already have secure end-to-end connections to origin servers. When you add field-level encryption, you can protect specific data throughout system processing in addition to HTTPS security, so that only certain applications at your origin can see the data.
To set up field-level encryption, you add a public key to CloudFront, and then specify the set of fields that you want to be encrypted with the key. For more information, see Using field-level encryption to help protect sensitive data (p. 236).
Customize at the edge
Running serverless code at the edge opens up a number of possibilities for customizing the content and experience for viewers, at reduced latency. For example, you can return a custom error message when your origin server is down for maintenance, so viewers don't get a generic HTTP error message.
Or you can use a function to help authorize users and control access to your content, before CloudFront forwards a request to your origin.
Using Lambda@Edge with CloudFront enables a variety of ways to customize the content that CloudFront delivers. To learn more about Lambda@Edge and how to create and deploy functions with CloudFront, see Customizing at the edge with Lambda@Edge (p. 366). To see a number of code samples that you can customize for your own solutions, see Lambda@Edge example functions (p. 411).
Serve private content by using Lambda@Edge customizations
Using Lambda@Edge can help you configure your CloudFront distribution to serve private content from your own custom origin, in addition to using signed URLs or signed cookies.
To serve private content using CloudFront, you do the following:
• Require that your users (viewers) access content using signed URLs or signed cookies (p. 164).
• Restrict access to your origin so that it’s only available from CloudFront’s origin-facing servers. To do this, you can do one of the following:
• For an Amazon S3 origin, you can use an origin access identity (OAI) (p. 221).
• For a custom origin, you can do the following:
• If the custom origin is protected by an Amazon VPC security group or AWS Firewall Manager, you can use the CloudFront managed prefix list (p. 8) to allow inbound traffic to your origin from only CloudFront’s origin-facing IP addresses.
• Use a custom HTTP header to restrict access to only requests from CloudFront. For more information, see the section called “ Restricting access to files on custom origins” (p. 166) and the section called “Adding custom headers to origin requests” (p. 306). For an example that uses a custom header to restrict access to an Application Load Balancer origin, see the section called
“Restricting access to Application Load Balancers” (p. 226).
How CloudFront delivers content
• If the custom origin requires custom access control logic, you can use Lambda@Edge to implement that logic, as described in this blog post: Serving Private Content Using Amazon CloudFront & Lambda@Edge.
How CloudFront delivers content
After some initial setup, CloudFront works together with your website or application and speeds up delivery of your content. This section explains how CloudFront serves your content when viewers request it.
Topics
• How CloudFront delivers content to your users (p. 5)
• How CloudFront works with regional edge caches (p. 6)
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.
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:
a. 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.
b. The origin server sends the object back to the edge location.
c. 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.
How CloudFront works with regional edge caches
CloudFront points of presence (also known as POPs or edge locations) make sure that popular content can be served quickly to your viewers. CloudFront also has regional edge caches that bring more of your content closer to your viewers, even when the content is not popular enough to stay at a POP, to help improve performance for that content.
Regional edge caches help with all types of content, particularly content that tends to become less popular over time. Examples include user-generated content, such as video, photos, or artwork; e- commerce assets such as product photos and videos; and news and event-related content that might suddenly find new popularity.
How regional caches work
Regional edge caches are CloudFront locations that are deployed globally, close to your viewers. They’re located between your origin server and the POPs—global edge locations that serve content directly to viewers. As objects become less popular, individual POPs might remove those objects to make room for more popular content. Regional edge caches have a larger cache than an individual POP, so objects remain in the cache longer at the nearest regional edge cache location. This helps keep more of your content closer to your viewers, reducing the need for CloudFront to go back to your origin server, and improving overall performance for viewers.
When a viewer makes a request on your website or through your application, DNS routes the request to the POP that can best serve the user’s request. This location is typically the nearest CloudFront edge location in terms of latency. In the POP, 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, the POP typically goes to the nearest regional edge cache to fetch it. For more information about when the POP skips the regional edge cache and goes directly to the origin, see the following note.
In the regional edge cache location, CloudFront again checks its cache for the requested object. If the object is in the cache, CloudFront forwards it to the POP that requested it. As soon as the first
How CloudFront works with regional edge caches
byte arrives from regional edge cache location, CloudFront begins to forward the object to the user.
CloudFront also adds the object to the cache in the POP for the next time someone requests it.
For objects not cached at either the POP or the regional edge cache location, CloudFront compares the request with the specifications in your distributions and forwards the request to the origin server. After your origin server sends the object back to the regional edge cache location, it is forwarded to the POP, and then CloudFront forwards it to the user. In this case, CloudFront also adds the object to the cache in the regional edge cache location in addition to the POP for the next time a viewer requests it. This makes sure that all of the POPs in a region share a local cache, eliminating multiple requests to origin servers.
CloudFront also keeps persistent connections with origin servers so objects are fetched from the origins as quickly as possible.
Note
• Regional edge caches have feature parity with POPs. For example, a cache invalidation request removes an object from both POP caches and regional edge caches before it expires. The next time a viewer requests the object, CloudFront returns to the origin to fetch the latest version of the object.
• Proxy HTTP methods (PUT, POST, PATCH, OPTIONS, and DELETE) go directly to the origin from the POPs and do not proxy through the regional edge caches.
• Dynamic requests, as determined at request time, do not flow through regional edge caches, but go directly to the origin.
• When the origin is an Amazon S3 bucket and the request’s optimal regional edge cache is in the same AWS Region as the S3 bucket, the POP skips the regional edge cache and goes directly to the S3 bucket.
The following diagram illustrates how requests and responses flow through CloudFront edge locations and regional edge caches.
Locations and IP address ranges of CloudFront edge servers
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. For more information, see AWS IP address ranges in the Amazon Web Services General Reference.
To find the IP address ranges that are associated with CloudFront edge servers, search ip-ranges.json for the following string:
"service": "CLOUDFRONT"
Alternatively, you can view only the CloudFront IP ranges at https://d7uri8nf7uskq.cloudfront.net/tools/
list-cloudfront-ips.
Use the CloudFront managed prefix list
The CloudFront managed prefix list contains the IP address ranges of all of CloudFront’s globally distributed origin-facing servers. If your origin is hosted on AWS and protected by an Amazon VPC security group, you can use the CloudFront managed prefix list to allow inbound traffic to your origin only from CloudFront’s origin-facing servers, preventing any non-CloudFront traffic from reaching your origin. CloudFront maintains the managed prefix list so it’s always up to date with the IP addresses of all of CloudFront’s global origin-facing servers. With the CloudFront managed prefix list, you don’t need to read or maintain a list of IP address ranges yourself.
For example, imagine that your origin is an Amazon EC2 instance in the Europe (London) Region (eu- west-2). If the instance is in a VPC, you can create a security group rule that allows inbound HTTPS access from the CloudFront managed prefix list. This allows all of CloudFront’s global origin-facing servers to reach the instance. If you remove all other inbound rules from the security group, you prevent any non-CloudFront traffic from reaching the instance.
The CloudFront managed prefix list is named com.amazonaws.global.cloudfront.origin-facing. This prefix list is available for use in all AWS Regions except for Asia Pacific (Jakarta) (ap-southeast-3) and Asia Pacific (Osaka) (ap-northeast-3). For more information, see Use an AWS-managed prefix list in the Amazon VPC User Guide.
Important
The CloudFront managed prefix list is unique in how it applies to Amazon VPC quotas. For more information, see AWS-managed prefix list weight in the Amazon VPC User Guide.
Accessing CloudFront
You can access Amazon CloudFront in the following ways:
• AWS Management Console – The procedures throughout this guide explain how to use the AWS Management Console to perform tasks.
• AWS SDKs – If you're using a programming language that AWS provides an SDK for, you can use an SDK to access CloudFront. SDKs simplify authentication, integrate easily with your development environment, and provide access to CloudFront commands. For more information, see Tools for Amazon Web Services.
How to get started with Amazon CloudFront
• CloudFront API – If you're using a programming language that an SDK isn't available for, see the Amazon CloudFront API Reference for information about API actions and about how to make API requests.
• AWS Command Line Interface – For more information, see Getting Set Up with the AWS Command Line Interface in the AWS Command Line Interface User Guide.
• AWS Tools for Windows PowerShell – For more information, see Setting up the AWS Tools for Windows PowerShell in the AWS Tools for Windows PowerShell User Guide.
How to get started with Amazon CloudFront
For information about getting started with Amazon CloudFront, see the following topics in this guide:
• Setting up Amazon CloudFront (p. 16), which explains how to sign up for AWS, how to secure access to your AWS account, and how to set up programmatic access to CloudFront.
• Getting started with Amazon CloudFront (p. 20), which describes how to create a distribution that can serve content to viewers from your origin, like an Amazon S3 bucket or a website, and then test that it works.
AWS Identity and Access Management
Amazon CloudFront integrates with AWS Identity and Access Management (IAM), a service that lets your organization do the following:
• Create users and groups under your organization's AWS account
• Easily share your AWS account resources among the users in the account
• Assign unique security credentials to each user
• Granularly control user access to services and resources
For example, you can use IAM with CloudFront to control which users in your AWS account can create a new distribution or update cache behavior settings.
For general information about IAM, see the following:
• Identity and Access Management (IAM) in CloudFront (p. 518)
• Identity and Access Management (IAM)
• IAM User Guide
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. As with the other AWS services, you pay as you go and pay only for what you use. For information about prices, see Amazon CloudFront Pricing.
TipTo avoid surprise charges from CloudFront (or any AWS service), you can use AWS Budgets. With AWS Budgets you can set cost thresholds and get notifications by email or Amazon SNS topic when your actual or forecasted charges exceed a threshold. For more information, see Managing
your costs with AWS Budgets and Creating a budget in the AWS Billing and Cost Management User Guide. To get started, go to AWS Budgets in the console.
AWS provides two usage reports for CloudFront: a billing report and a report that summarizes usage activity. To learn more about these reports, see AWS billing and usage reports for CloudFront (p. 444).
The following diagram and list summarize the charges to use CloudFront.
Your monthly bill from AWS allocates your usage and dollar amounts by AWS service and function. The following explains the charges that are illustrated in the previous graphic. For more information about prices, see Amazon CloudFront Pricing.
1.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.
2.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 data from server to client. The CloudFront charges appear in the CloudFront portion of your AWS statement as region -DataTransfer-Out-Bytes.
3.Charge for submitting data to your origin. You incur CloudFront charges when users transfer data to your origin, which includes DELETE, OPTIONS, PATCH, POST, and PUT requests. The charges
Savings bundle
include data transfer for WebSocket data from client to server. The CloudFront charges appear in the CloudFront portion of your AWS statement as region -DataTransfer-Out-OBytes.
Be aware of the following:
• You also incur a surcharge for HTTPS requests, and an additional surcharge for requests that also have field-level encryption enabled or that use Origin Shield (p. 248) as an incremental caching layer. For more information about prices, see Amazon CloudFront Pricing.
• You do not incur any additional CloudFront charges when you use origin groups. You continue to pay the same request fees and data transfer rates as you do when you use CloudFront with any other AWS or non-AWS origin. For more information, see Using CloudFront origin groups (p. 72).
CloudFront security savings bundle
The CloudFront security savings bundle is a simple way to save up to 30% on the CloudFront charges on your AWS bill when you make an upfront commitment. When you purchase a savings bundle, you also get credits for AWS WAF, a web application firewall that helps protect your CloudFront distribution against common web exploits.
For more information, see the following sections. To purchase a savings bundle, go the savings bundle overview page in the CloudFront console.
Sections
• Savings bundle overview (p. 11)
• Savings bundle example (p. 11)
• Purchasing a savings bundle (p. 12)
• Viewing and updating your savings bundles (p. 12)
• Permissions to manage a savings bundle (p. 13)
• More information about savings bundles (p. 13)
Savings bundle overview
Here’s how the CloudFront security savings bundle works:
1. To purchase a savings bundle, you commit to pay a consistent monthly amount (dollars per month) for CloudFront for one year. You are billed for the committed amount each month, for 12 months, starting in the billing period in which you purchase the savings bundle. If you purchase a savings bundle on the last day of the billing period, the charges and credits begin the following billing period.
2. In exchange for your commitment, CloudFront automatically applies credits to your AWS bill in each of the 12 billing periods of the one year term. The value of these credits is more than your committed payment amount, resulting in up to a 30% discount on CloudFront’s standard pricing for the committed amount. These credits automatically offset CloudFront charges on your AWS bill. For a detailed example, see the following section.
3. In addition to the CloudFront credits, you get credits to offset the per-request charges for using AWS WAF. The amount of the AWS WAF credits is up to 10% of the amount of the monthly CloudFront commitment. For more information about using AWS WAF with CloudFront, see Using AWS WAF to control access to your content (p. 232).
Savings bundle example
Consider a scenario in which your CloudFront usage charges are typically $600 per month. To take full advantage of the CloudFront security savings bundle, you commit pay $420 for CloudFront each
month for one year. This is 30% less than your typical usage charges ($600 x 0.7). In exchange for this commitment, CloudFront gives you $600 worth of credits that apply to the CloudFront charges on your monthly AWS bill for each of the next 12 billing periods. These credits automatically apply to your CloudFront charges, which continue to appear on the bill at standard rates. In effect, you pay a cost of
$420 per month for $600 per month of CloudFront usage.
In addition, you get $42 in AWS WAF credits to offset the AWS WAF request charges for using AWS WAF with your CloudFront distribution.
When you purchase a CloudFront security savings bundle at a monthly commitment of $420, your estimated total annual savings is up to $2,664.
Purchasing a savings bundle
To purchase a savings bundle, go to the savings bundle overview page in the CloudFront console and choose Get started.
In the first step, the console shows a recommended monthly commitment amount based on your historical usage of CloudFront over the past few months. You can choose the Calculator tab to use the usage calculator to enter your estimated CloudFront usage and receive a recommended monthly commitment amount based on your estimates.
After you view your recommended commitment and choose Next, you can choose the amount of your monthly commitment and whether to automatically renew your savings plan each year. You can see a summary of the benefits based on your monthly commitment amount.
Choose Next to review and then purchase your CloudFront security savings bundle.
Viewing and updating your savings bundles
To view or update the savings bundles that you purchased, go to the savings bundle inventory page in the CloudFront console. This page shows the savings bundles that you purchased, and allows you to enable or disable the automatic renewal of a purchased savings bundle.
Savings bundle
You can purchase more than one savings bundle, and you can have multiple savings bundles that are active at the same time. If you purchase a savings bundle and then find that your monthly CloudFront usage consistently exceeds the credits in the bundle, you can purchase another bundle to get additional savings.
Permissions to manage a savings bundle
To manage a CloudFront security savings bundle, the IAM identity must have the required permissions.
Identities with full access to CloudFront (cloudfront:*) inherit these permissions automatically. For other identities, you can add the following permissions manually:
• The following read-only permissions allow the identity to get information related to existing CloudFront security savings bundles, including the information necessary to view recommendations and estimated savings in the CloudFront console:
• cloudfront:ListSavingsPlans
• cloudfront:GetSavingsPlan
• cloudfront:ListRateCards
• cloudfront:ListUsages
• cloudfront:CreateSavingsPlan – Allows the identity to purchase a CloudFront security savings bundle.
• cloudfront:UpdateSavingsPlan – Allows the identity to enable or disable the automatic renewal of a purchased CloudFront security savings bundle.
More information about savings bundles
Use the following questions and answers to help you understand additional details about CloudFront security savings bundles.
Do the savings bundle credits apply to a specific distribution or all distributions?
The credits apply at the AWS account level to all CloudFront usage in the AWS account.
Do the credits apply to all types of CloudFront usage?
Yes. The credits apply to all CloudFront charges, including data transfer charges, request charges, and Lambda@Edge charges.
Can I use a CloudFront security savings bundle with consolidated billing?
Yes, as long as credit sharing is enabled (you can verify this by viewing the billing preferences page in the AWS Billing and Cost Management console). You purchase the savings bundle with the payer account (management account). The credits apply first to any CloudFront charges accrued in the payer account, and then to CloudFront charges accrued in the member accounts, depending on when the account joins or leaves an organization. For more information about how AWS credits apply across single and multiple accounts, see AWS credits in the AWS Billing and Cost Management User Guide.
What if I don’t use all the credits in a given billing period?
Credits are applied to your AWS bill each billing period, and must be used in that billing period. If any credits are left unused at the end of the billing period, they expire. Credits do not carry over to the following billing period.
What if my CloudFront or AWS WAF usage exceeds the amount of the credits?
The CloudFront and AWS WAF charges that you accrue are offset by the credits from the CloudFront security savings bundle. If your usage exceeds the available credits for that billing period, you are billed for the difference at standard rates.
Are the charges or credits prorated for partial months?
No. When you purchase a CloudFront security savings plan, the charge is applied to your bill for the current billing period. Likewise, the credits are applied to the charges for the current billing period. If you purchase a savings bundle on the last day of the billing period, the charges and credits begin the following billing period (the next day).
What happens when the savings bundle expires?
You can choose whether to automatically renew the bundle at the end of the one year term. If you choose not to automatically renew, the savings bundle expires after the one year term. When that happens, the credits no longer apply to your AWS bill and you are charged for CloudFront and AWS WAF usage at standard rates.
Can I get notifications if my CloudFront usage exceeds the amount covered by the savings bundle credits?
Yes. With AWS Budgets, you can set cost or usage thresholds. When your actual or forecasted charges for CloudFront exceed a threshold, you get notifications by email or Amazon SNS topic. You can create a custom budget filtered for CloudFront and set the budget threshold amount to the usage covered by your CloudFront security savings bundle. For more information, see Managing your costs with AWS Budgets and Creating a budget in the AWS Billing and Cost Management User Guide.
To get started, go to AWS Budgets in the console.
How does the CloudFront security savings bundle appear on my bill?
The charges for your commitment amount appear in the CloudFront Security Bundle section of your monthly bill. The credits appear in the CloudFront and AWS WAF section of your bill with the description Usage covered by CloudFront Security Savings Bundle.
For more information, see Amazon CloudFront Pricing on the AWS website.
Choosing the price class for a CloudFront distribution
CloudFront has edge locations all over the world. Our cost for each edge location varies and, as a result, the price that we charge varies depending on which edge location serves the requests.
CloudFront edge locations are grouped into geographic regions, and we’ve grouped regions into price classes as shows in the following table. You choose a price class when you create (p. 41) or update (p. 66) a CloudFront distribution.
North
America (United States, Mexico, Canada)
Europe and Israel
South Africa, Kenya, and the Middle East
South
America Japan Australia and New Zealand
HongKong, Indonesia, the
Philippines, Singapore, South Korea, Taiwan, andThailand
India
Price
Class All Yes Yes Yes Yes Yes Yes Yes Yes
Price Class 200
Yes Yes Yes No Yes No Yes Yes
Choosing the price class for a CloudFront distribution
North
America (United States, Mexico, Canada)
Europe and Israel
South Africa, Kenya, and the Middle East
South
America Japan Australia and New Zealand
Hong Kong, Indonesia, the
Philippines, Singapore, South Korea, Taiwan, andThailand
India
Price Class 100
Yes Yes No No No No No No
By default, CloudFront responds to requests based only on performance. Objects are served from the edge location that has the lowest latency for the viewer. If you’re willing to accept potentially higher latency for viewers in some geographic regions in return for lower cost, you can choose a price class that doesn’t include all geographic regions. Some viewers, especially those in geographic regions that are not in your price class, might see higher latency than if your content was served from all CloudFront edge locations. For example, if you choose Price Class 100, viewers in India might experience higher latency than if you choose Price Class 200.
If you choose a price class that doesn’t include all edge locations, CloudFront might still occasionally serve requests from an edge location in a region that is not included in your price class. When this happens, you are not charged the rate for the more expensive region. Instead, you’re charged the rate for the least expensive region in your price class.
For more information about CloudFront pricing and price classes, see Amazon CloudFront Pricing.
Setting up Amazon CloudFront
The overview and procedures in this section help you get started with AWS.
Topics
• Sign up for AWS (p. 16)
• Access your account (p. 16)
• Create an IAM user (p. 17)
• Set up the AWS Command Line Interface or AWS Tools for Windows PowerShell (p. 19)
• Download an AWS SDK (p. 19)
Sign up for AWS
When you sign up for AWS, your AWS account is automatically signed up for all services in AWS, including Amazon CloudFront. You are charged only for the services that you use.
If you have an AWS account already, skip to Access your account (p. 16). Otherwise, create one.
To create an AWS account
1. Open https://portal.aws.amazon.com/billing/signup.
2. Follow the online instructions.
Part of the sign-up procedure involves receiving a phone call and entering a verification code on the phone keypad.
Note your AWS account number, because you'll need it later.
TipIf you plan to use CloudFront to distribute content that you store in an S3 bucket, make sure that you also complete the steps to sign up for S3. For more information, see Sign Up for Amazon S3.
Access your account
You use AWS services by using any of the following options:
• AWS Management Console
• API for each service
• AWS Command Line Interface (AWS CLI)
• AWS Tools for Windows PowerShell
• AWS SDKs
For each of those options, you need to access your AWS account by providing credentials that verify that you have permissions to use the services.
Access the console
Access the console
To access the AWS Management Console for the first time, you provide an email address and a password.
This combination of your email address and password is called your root identity or root account credentials. After you access your account for the first time, we strongly recommend that you don't use your root account credentials again for everyday use. Instead, you should create new credentials by using AWS Identity and Access Management. To do that, you create a user account for yourself known as an IAM user, and then add the IAM user to an IAM group with administrative permissions or grant the IAM user administrative permissions. You then can access AWS using a special URL and the credentials for the IAM user. You also can add other IAM users later, and restrict their access to specified resources in the account.
NoteSome ad-blocking plugins for web browsers interfere with Amazon CloudFront console
operations, which can cause the console to behave unpredictably. If you installed an ad-blocking plugin for your browser, we recommend that you add the URL for the CloudFront console, https://console.aws.amazon.com/cloudfront/v3/home, to the whitelist for the plugin.
Access the API, AWS CLI, AWS Tools for Windows PowerShell, or the AWS SDKs
To use the API, the AWS CLI, AWS Tools for Windows PowerShell, or the AWS SDKs, you must create access keys. These keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS.
To create the keys, you sign in to the AWS Management Console. We strongly recommend that you sign in with your IAM user credentials instead of your root credentials. For more information, see Managing Access Keys for IAM Users in the IAM User Guide.
Create an IAM user
Use the following procedures to create a group for administrators, create an IAM user, and then add the IAM user to the administrators group. If you signed up for AWS but have not created an IAM user for yourself, you can create one using the IAM console. If you aren't familiar with using the console, see Working with the AWS Management Console for an overview.
To create an administrator user for yourself and add the user to an administrators group (console)
1. Sign in to the IAM console as the account owner by choosing Root user and entering your AWS account email address. On the next page, enter your password.
NoteWe strongly recommend that you adhere to the best practice of using the Administrator IAM user that follows and securely lock away the root user credentials. Sign in as the root user only to perform a few account and service management tasks.
2. In the navigation pane, choose Users and then choose Add user.
3. For User name, enter Administrator.
4. Select the check box next to AWS Management Console access. Then select Custom password, and then enter your new password in the text box.
5. (Optional) By default, AWS requires the new user to create a new password when first signing in. You can clear the check box next to User must create a new password at next sign-in to allow the new user to reset their password after they sign in.
6. Choose Next: Permissions.
7. Under Set permissions, choose Add user to group.
8. Choose Create group.
9. In the Create group dialog box, for Group name enter Administrators.
10. Choose Filter policies, and then select AWS managed - job function to filter the table contents.
11. In the policy list, select the check box for AdministratorAccess. Then choose Create group.
Note
You must activate IAM user and role access to Billing before you can use the
AdministratorAccess permissions to access the AWS Billing and Cost Management console. To do this, follow the instructions in step 1 of the tutorial about delegating access to the billing console.
12. Back in the list of groups, select the check box for your new group. Choose Refresh if necessary to see the group in the list.
13. Choose Next: Tags.
14. (Optional) Add metadata to the user by attaching tags as key-value pairs. For more information about using tags in IAM, see Tagging IAM entities in the IAM User Guide.
15. Choose Next: Review to see the list of group memberships to be added to the new user. When you are ready to proceed, choose Create user.
You can use this same process to create more groups and users and to give your users access to your AWS account resources. To learn about using policies that restrict user permissions to specific AWS resources, see Access management and Example policies.
To sign in as your new IAM user 1. Sign out of the AWS console.
2. Sign in by using the following URL, where your_account_id is your AWS account number without the hyphens. For example, if your AWS account number is 1234-5678-9012, your AWS account ID is 123456789012:
https://your_account_id.signin.aws.amazon.com/console/
3. Enter the IAM user name (not your email address) and password that you just created. When you're signed in, the navigation bar displays "your_user_name @ your_account_id".
If you don't want the URL for your sign-in page to contain your AWS account ID, you can create an account alias.
To create an account alias and conceal your account ID 1. On the IAM console, choose Dashboard in the navigation pane.
2. On the dashboard, choose Customize and enter an alias such as your company name.
3. Sign out of the AWS console.
4. Sign in by using the following URL:
https://your_account_alias.signin.aws.amazon.com/console/
To verify the sign-in link for IAM users for your account, open the IAM console and check under IAM users sign-in link on the dashboard.
For more information about using IAM, see Identity and Access Management (IAM) in CloudFront (p. 518).
Set up the AWS Command Line Interface or AWS Tools for Windows PowerShell
Set up the AWS Command Line Interface or AWS Tools for Windows PowerShell
The AWS Command Line Interface (AWS CLI) is a unified tool for managing AWS services. For information about how to install and configure the AWS CLI, see Getting Set Up with the AWS Command Line
Interface in the AWS Command Line Interface User Guide.
If you have experience with Windows PowerShell, you might prefer to use AWS Tools for Windows PowerShell. For more information, see Setting up the AWS Tools for Windows PowerShell in the AWS Tools for Windows PowerShell User Guide.
Download an AWS SDK
If you're using a programming language that AWS provides an SDK for, we recommend that you use an SDK instead of the Amazon CloudFront API. The SDKs make authentication simpler, integrate easily with your development environment, and provide easy access to CloudFront commands. For more information, see Tools to Build on AWS.
Getting started with Amazon CloudFront
Get started with the basic steps to deliver your content with CloudFront by creating a simple CloudFront distribution, using the AWS for WordPress plugin, or creating a secure static website. If you already have a WordPress website, we recommend using the AWS for WordPress plugin to create a CloudFront distribution.
Topics
• Getting started with a simple CloudFront distribution (p. 20)
• Getting started with the AWS for WordPress plugin (p. 23)
• Getting started with a secure static website (p. 32)
Getting started with a simple CloudFront distribution
The procedures in this section show you how to use CloudFront to set up a basic configuration that does the following:
• Stores the original versions of your objects in an Amazon Simple Storage Service (Amazon S3) bucket
• Makes your objects accessible to everyone
• Uses the CloudFront domain name in URLs for your objects (for example, http://
d111111abcdef8.cloudfront.net/index.html)
• Keeps your objects in CloudFront edge locations for the default duration of 24 hours (the minimum duration is 0 seconds)
Most of these options are customizable. For example, you can store your content on your own web server instead of using an S3 bucket, and you can restrict who has access to the content by using signed URLs or cookies. For information about how to customize your CloudFront distribution options, see Steps for creating a distribution (overview) (p. 40).
You have to complete only a few basic steps to start delivering your content with CloudFront. The first step is signing up. After that, you create a CloudFront distribution, and then use the CloudFront domain name in URLs in your webpages or applications to reference the content.
Topics
• Prerequisites (p. 20)
• Step 1: Upload your content to Amazon S3 and grant object permissions (p. 21)
• Step 2: Create a CloudFront distribution (p. 22)
• Step 3: Access your content through CloudFront (p. 22)
Prerequisites
Before you begin, make sure that you’ve completed the steps in Setting up Amazon CloudFront (p. 16).
Step 1: Upload your content to Amazon S3 and grant object permissions
Step 1: Upload your content to Amazon S3 and grant object permissions
An Amazon S3 bucket is a container for files (objects) or folders. CloudFront can distribute almost any type of file for you using an Amazon S3 bucket as the source. For example, CloudFront can distribute text, images, and videos. There is no maximum for the amount of data that you can store on Amazon S3.
By default, your Amazon S3 bucket and all the files in it are private—only the AWS account that created the bucket has permission to read or write the files. If you want to allow anyone to access the files in your Amazon S3 bucket using CloudFront URLs, you must grant public read permissions to the objects.
NoteIf you want to restrict who can download your content, you can use the CloudFront private content feature. For more information about distributing private content, see Serving private content with signed URLs and signed cookies (p. 164).
To upload your content to Amazon S3 and grant read permissions to everyone
1. Sign in to the AWS Management Console and open the Amazon S3 console at https://
console.aws.amazon.com/s3/.
2. Choose Create bucket.
3. For Bucket name, enter a bucket name.
Important
For your bucket to work with CloudFront, the name must conform to DNS naming
requirements. For more information, see Bucket restrictions and limitations in the Amazon Simple Storage Service User Guide.
4. For Region, choose an AWS Region for your bucket. We recommend that you choose a Region close to you to optimize latency and minimize costs, or you might choose another Region to address regulatory requirements.
5. In the Block Public Access settings for bucket section, clear the check box for Block all public access.
You must allow public read access to the bucket and files so that CloudFront URLs can serve content from the bucket. However, you can restrict access to specific content by using the CloudFront private content feature. For more information, see Serving private content with signed URLs and signed cookies (p. 164).
Select the check box for I acknowledge that the current settings might result in this bucket and the objects within becoming public..
6. Leave all other settings at their defaults, and then choose Create bucket.
7. (Optional) If you don’t have your own website content, or if you just want to experiment with CloudFront before uploading your own content, use the following link to download a simple hello world webpage: hello-world-html.zip.
8. In the Buckets section, choose your new bucket, and then choose Upload.
9. Use the Upload page to add your content to the S3 bucket. If you downloaded the simple hello world webpage, add the index.html file and the css folder (with the style.css file inside it).
10. Choose Additional upload options to expand the section.
11. In the Access control list (ACL) section, select the check box for Read next to Everyone (public access) in the Objects column.
12. Select the check box for I understand the effects of these changes on the specified objects.
13. At the bottom of the page, choose Upload.
After the upload is complete, you can navigate to the item by using its URL. For example:
https://<bucket name>.s3-<AWS Region>.amazonaws.com/<object name>
Replace <bucket name>, <AWS Region>, and <object name> with the appropriate values based on your bucket and content. If you used the simple hello world website in this procedure, replace
<object name> with index.html.
NoteIf you created the bucket in the US East (N. Virginia) Region (us-east-1), omit the <AWS Region> portion of the URL. For example:
https://<bucket name>.s3.amazonaws.com/<object name>
Use the Amazon S3 URL to verify that your content is publicly accessible, but remember that this is not the URL you’ll use to access your content with CloudFront.
Step 2: Create a CloudFront distribution
To create a CloudFront distribution
1. Open the CloudFront console at https://console.aws.amazon.com/cloudfront/v3/home.
2. Choose Create Distribution, and then choose Get Started.
3. Under Origin Settings, for Origin Domain Name, choose the Amazon S3 bucket that you created earlier.
For the other settings under Origin Settings, accept the default values.
4. For the settings under Default Cache Behavior Settings, accept the default values.
For more information about cache behavior options, see Cache behavior settings (p. 50).
5. For the settings under Distribution Settings, accept the default values.
For more information about distribution options, see Distribution settings (p. 57).
6. At the bottom of the page, choose Create Distribution.
7. After CloudFront creates your distribution, the value of the Status column for your distribution changes from In Progress to Deployed. This typically takes a few minutes.
Record the domain name that CloudFront assigns to your distribution, which appears in the list of distributions. (It also appears on the General tab for a selected distribution.) It looks similar to the following: d111111abcdef8.cloudfront.net.
Step 3: Access your content through CloudFront
To access your content through CloudFront, combine your CloudFront distribution domain name with the path to access your content. For example, your distribution domain name looks similar to the following:
d111111abcdef8.cloudfront.net. Traditionally, the path to access the main page of a website is / index.html. In this case, you could access your content through CloudFront at a URL that looks similar to the following:
https://d111111abcdef8.cloudfront.net/index.html
If you followed the previous steps and used the simple hello world webpage, you should see the webpage’s content: