Ao usar o AWS re:Post, você concorda com os AWS re:Post Termos de uso

How to prevent Cloudfront to cache some types of files?

0

Hi,

Currently we only want to use Cloudfront to cache .EXE files. For all other types of files, we do NOT want to cache them. However, it seems that Cloudfront will cache all files. And one of my sitemap file at https://www.datanumen.com/sitemap_index.xml is also cached by Cloudfront as https://download.datanumen.com/sitemap_index.xml. How to prevent that?

feita há 8 meses890 visualizações
5 Respostas
1

To disable caching completely, go to CloudFront console, click on the ID value of your CloudFront distribution and navigate to Behaviors section. Select and edit the default entry. Your CachePolicy is probably set to CachingOptimized. Change it to CachingDisabled and save.

To cache only .EXE file, click Create behavior to create a new entry. Use *.exe for Path pattern and set CachePolicy to CachingOptimized

Your configuration should be similar to screenshot below Enter image description here

Since your files are already cached, you may want to clear CloudFront cache as well. Go to Invalidations section and click Create invalidation

Edit: Your configuration looks correct. *.exe files are cached as per curl command below

% curl -I https://download.datanumen.com/downloads/file/daccr.exe
HTTP/2 200
...
vary: Accept-Encoding
x-cache: Hit from cloudfront
...

Others are not cached by CloudFront

% curl -I https://download.datanumen.com/
HTTP/2 200
...
x-cache: Miss from cloudfront

Any caching if any is by your origin (www.datanumen.com). It is using Cloudflare. Suggest you change your CloudFront origin to your EC2 (?) domain name.

AWS
ESPECIALISTA
respondido há 8 meses
0

Hi,

I check my distribution and find it already have a behavior, so I think the most simple way is to edit it and change the pattern from * to *.exe, as below: Enter image description here

But I cannot make the change. Why?

respondido há 8 meses
  • Do not change path pattern for this (Default). Only change CachePolicy to CachingDisabled. Instead, create a new behavior with the same values except for path pattern (*.exe) and caching policy (CachingDisabled). I have updated my post with screenshot

0

Hi, Mike

I just follow your instructions, except that we have a custom cache policy with our own defined settings, below is my setting: Enter image description here And I have clear the cache as below: Enter image description here

But, when visiting https://download.datanumen.com (the domain used by Amazon Cloudfront), I will still see our company page. Am I doing something wrong?

respondido há 8 meses
  • Alan, when I go to the following URL (https://download.datanumen.com/sitemap_index.xml), I see that the object is not being cached. CloudFront is returning a 200 (not a 304), and the X-Cache header returns "Miss from cloudfront". It looks like caching is working as expected. What are you expecting to see?

0

Hello.

I think the following documents will be helpful.
https://repost.aws/knowledge-center/prevent-cloudfront-from-caching-files

I thought it would be a good idea to target only ".exe" by setting the cache key etc.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html

profile picture
ESPECIALISTA
respondido há 8 meses
profile picture
ESPECIALISTA
avaliado há 8 meses
0

I recommend following Mike L's instructions, that is exactly what you need to do.

To elaborate, CloudFront uses Behaviors, and you can think of them as rules. They have an order of execution, with 0 being first, 1 next, then 2, etc. Inside a Behavior you define what path you want to match on, in this case *.exe. You also can define other things, such as a caching policy, which origin to use, etc.

profile pictureAWS
respondido há 8 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas