Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know we can set the expires header to Amazon S3, but how do I set it for a cloudfront file ? I've read that we can set the TTL from 24hrs to 1hr, but I want to set it for 1 year.

share|improve this question

2 Answers 2

This is handled with the regular HTTP cache control mechanisms (see RFC 2616) as documented in Amazon CloudFront Object Expiration, specifically:

By default, each object automatically expires after 24 hours. To specify a different expiration time, configure your origin to add a value for either the Cache-Control max-age directive or the Expires header field to each object:

  • The Cache-Control max-age directive lets you specify how long (in seconds) you want the object to remain in the cache before CloudFront gets the object again from the origin server. The minimum expiration time CloudFront supports is 0 seconds for web distributions and 3600 seconds for RTMP distributions. The maximum is in the year 2038. Specify the value in the following format:

    Cache-Control: max-age=seconds

    For example, the following directive tells CloudFront to keep the associated object in the cache for 3600 seconds (one hour):

    Cache-Control: max-age=3600

    If you want objects to stay in CloudFront edge caches for a different duration than they stay in browser caches, you can use the Cache-Control max-age and Cache-Control s-maxage directives together. For more information, see Specifying the Minimum Time that CloudFront Caches Objects for Web Distributions.

  • The Expires header field lets you specify an expiration date and time using the format specified in RFC 2616, Hypertext Transfer Protocol -- HTTP/1.1 Section 3.3.1, Full Date, for example:

    Sat, 30 Jun 2012 23:59:59 GMT

    [...]

We recommend that you use the Cache-Control max-age directive instead of the Expires header field to control object caching. If you specify values both for Cache-Control max-age and for Expires, CloudFront uses only the value of max-age. [emphasis mine]

You might also want to have a look at the table within Specifying the Minimum Time that CloudFront Caches Objects for Web Distributions to understand the peculiarities of the Minimum TTL = 0 (Default) (see my answer to What is a TTL 0 in CloudFront useful for? for a more detailed explanation of this feature).

share|improve this answer

Why do you want to do that? Do you think that by doing so your files will be held closer to the edge for a whole year without a single origin pull? If so then that simply won't happen sorry, 24 hours is actually quite a long time for a CDN. If you're worried about your files dropping off the edge just distribute some VMs around the world that just periodically get your content (we call it 'tickling'), keeping your content at the edge.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.