How do I prevent CloudFront from caching certain files?

Lesedauer: 2 Minute

I want Amazon CloudFront to pass certain files through, instead of caching the files at edge locations. How can I do that?


To prevent CloudFront from caching certain files, choose only one of the following configurations:

Configuration on the origin

Note: If you use legacy cache settings, then update your CloudFront distribution's cache behavior to set Object caching as Use Origin Cache Headers. If you use a cache policy, then CloudFront considers origin Cache-Control settings by default.

On your custom origin web server application, add Cache-Control no-cache, no-store, or private directives to the objects that you don't want CloudFront to cache. Or, add Expires directives to the objects that you don't want CloudFront to cache.

If you're using Amazon Simple Storage Service (Amazon S3) as the origin, you can add certain Cache-Control headers using object metadata.

Configuration on the distribution

1.    Open the CloudFront console.

2.    From your list of CloudFront distributions, choose the distribution that you want to modify.

3.    Choose the Behaviors tab.

4.    If you already have a cache behavior for the objects that you don't want CloudFront to cache, then select the cache behavior and choose Edit. To create a new cache behavior, choose Create Behavior.

5.    For Cache and origin request settings, select Cache policy and origin request policy (recommended).

6.    For Cache policy, select Managed - CachingDisabled.

7.    Choose Save changes to save the changes that you made.

Note: If you aren't using an Amazon S3 bucket as your origin, then you can set a specific cache behavior to forward all headers to the origin. To do this, update the cache behavior to set Cache Based on Selected Request Headers to All.

Related information

Specifying the amount of time that CloudFront caches objects

Adding, removing, or replacing content that CloudFront distributes

AWS OFFICIALAktualisiert vor 5 Monaten
Keine Kommentare