Amazon CloudFront
Developer Guide (API Version 2013-05-12)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Request and Response Behavior for Amazon S3 Origins

How CloudFront Processes and Forwards Requests to Your Amazon S3 Origin Server

For information about how CloudFront processes end-user requests and forwards the requests to your Amazon S3 origin, see the applicable topic:

HTTP Methods

CloudFront accepts only GET and HEAD requests from end users.

Query Strings

For download distributions, you can configure whether CloudFront forwards query string parameters to your Amazon S3 origin. For streaming distributions, CloudFront does not forward query string parameters. For more information, see How CloudFront Forwards, Caches, and Logs Query String Parameters.

Cookies

Amazon S3 doesn't process cookies. If you configure a cache behavior to forward cookies to an Amazon S3 origin, CloudFront forwards the cookies, but Amazon S3 ignores them.

Protocols

CloudFront forwards HTTP or HTTPS requests to the origin server based on the protocol of the request that the end user sends to CloudFront, either HTTP or HTTPS.

IP Addresses

The IP address that CloudFront forwards to Amazon S3 is the IP address of a CloudFront server, not the IP address of the end user's computer.

Caching Duration and Minimum TTL

For download distributions, to control how long your objects stay in a CloudFront cache before CloudFront forwards another request to your origin, you can:

  • Configure your origin to add a Cache-Control or an Expires header field to each object.

  • Specify a value for Minimum TTL in CloudFront cache behaviors.

  • Use the default value of 24 hours.

For more information, see Specifying How Long Objects Stay in a CloudFront Edge Cache (Object Expiration).

Conditional GETs

When CloudFront receives a request for an object that has expired from an edge cache, it forwards the request to the Amazon S3 origin either to get the latest version of the object or to get confirmation from Amazon S3 that the CloudFront edge cache already has the latest version. When Amazon S3 originally sent the object to CloudFront, it included an ETag value and a LastModified value in the response. In the new request that CloudFront forwards to Amazon S3, CloudFront adds one of the following:

  • An If-Match or If-None-Match header that contains the ETag value for the expired version of the object.

  • An If-Modified-Since header that contains the LastModified value for the expired version of the object.

Amazon S3 uses this information to determine whether the object has been updated and, therefore, whether to return the entire object to CloudFront or to return only an HTTP 304 status code (not modified).

Maximum Length of a Request and Maximum Length of a URL

The maximum length of a request, including the path, the query string (if any), and headers, is 20480 bytes.

CloudFront constructs a URL from the request. The maximum length of this URL is 8192 bytes.

If a request or a URL exceeds these limits, CloudFront drops the request.

How CloudFront Processes Responses from Your Amazon S3 Origin Server

Redirects

You can configure an Amazon S3 bucket to redirect all requests to another host name; this can be another Amazon S3 bucket or an HTTP server. If you configure a bucket to redirect all requests and if the bucket is the origin for a CloudFront distribution, we recommend that you configure the bucket to redirect all requests to a CloudFront distribution using either the domain name for the distribution (for example, d111111abcdef8.cloudfront.net) or an alternate domain name (a CNAME) that is associated with a distribution (for example, example.com). Otherwise, end user requests bypass CloudFront, and the objects are served directly from the new origin.

Note

If you redirect requests to an alternate domain name, you must also update the DNS service for your domain by adding a CNAME record. For more information, see Using Alternate Domain Names (CNAMEs).

Here's what happens when you configure a bucket to redirect all requests:

  1. A viewer (for example, a browser) requests an object from CloudFront.

  2. CloudFront forwards the request to the Amazon S3 bucket that is the origin for your distribution.

  3. Amazon S3 returns an HTTP status code 301 (Moved Permanently) as well as the new location.

  4. CloudFront caches the redirect status code and the new location, and returns the values to the viewer. CloudFront does not follow the redirect to get the object from the new location.

  5. The viewer sends another request for the object, but this time the viewer specifies the new location that it got from CloudFront:

    • If the Amazon S3 bucket is redirecting all requests to a CloudFront distribution, using either the domain name for the distribution or an alternate domain name, CloudFront requests the object from the Amazon S3 bucket or the HTTP server in the new location. When the new location returns the object, CloudFront returns it to the viewer and caches it in an edge location.

    • If the Amazon S3 bucket is redirecting requests to another location, the second request bypasses CloudFront. The Amazon S3 bucket or the HTTP server in the new location returns the object directly to the viewer, so the object is never cached in a CloudFront edge cache.

Maximum File Size

The maximum size of a response body that CloudFront will return to the end user is 20 GB. This includes chunked transfer responses that don't specify the Content-Length header value.