AWS re:Post을(를) 사용하면 다음에 동의하게 됩니다. AWS re:Post 이용 약관

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?

질문됨 8달 전906회 조회
5개 답변
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
전문가
답변함 8달 전
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?

답변함 8달 전
  • 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?

답변함 8달 전
  • 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
전문가
답변함 8달 전
profile picture
전문가
검토됨 8달 전
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
답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인