0
votes

I created a AWS CloudFront distribution with three origins with three different behaviors.

Here are my three buckets with region.

  1. Seoul - eimages
  2. Seoul - etxts
  3. Mumbai - epdfs

Each bucket has a single file

  1. eimages - Sample.jpg
  2. epdfs - Sample.pdf
  3. etxts - Sample.txt

Then I configure the CloudFront behavior as follows

  1. *.pdf - emages
  2. *.txt - etxts
  3. (*) default - eimages

Given that my CloudFront distribution domain is d3ewqer4qpe.cloudfront.net I tried hitting following URLs from the browser and Mumbai bucket is replying with AccessDenied.

<Error>
  <Code>AccessDenied</Code>
  <Message>Access Denied</Message>
  <RequestId>335922B75E760050</RequestId>
  <HostId>
a05u8gpKGGM8FjlVyQrMwOqhswEEw0KMR/HbH3S9lJX0MpAlMWsutYYI5ka3FxKeQnwvOdqeiqI=
  </HostId>
</Error>

As I can see the redirect URL as https://eimages.s3.ap-northeast-2.amazonaws.com/Sample.pdf. Seems request request redirected to wrong bucket. But if I try correcting the URL with correct bucket name and region then its working fine https://epdfs.s3.ap-south-1.amazonaws.com/Sample.pdf and as it seems cached at the edge location.

Any thought whats happening? Thanks in advance.

1
"As I can see the redirect URL as" your question does not make it clear how you are seeing this redirect URL. Where do you see this? What exact URL do I view through CloudFront to duplicate what you are seeing? - Michael - sqlbot
I saw it redirecting in the browser, I am hitting the URL https://d3ewqer4qpe.cloudfront.net/Sample.pdf and it resolved to https://eimages.s3.ap-northeast-2.amazonaws.com/Sample.pdf. As I don't have a pdf file in eimages it gives me AccessDenied. But if I use the correct URL which need to be redirected https://epdfs.s3.ap-south-1.amazonaws.com/Sample.pdf it works as expected. So this should be an issue with the behavior resolution issue at CloudFront. - Eranda
curl: (6) Couldn't resolve host 'd3ewqer4qpe.cloudfront.net' I can't bring this site up at all. Confirm that this is the correct hostname? - Michael - sqlbot

1 Answers

0
votes

Amazon CloudFront allows you to to remove one or multiple files from all edge locations prior to the expiration date set on those files.

The invalidation feature is helpful in unexpected circumstances, for instance an occasional update to your websites css file, in which you need to remove the file from Amazon CloudFront.

Invalidation can also be helpful in the event that offensive or potentially harmful material needs to be removed before the specified expiration time.

If you need to remove an object from CloudFront edge caches before it expires

Invalidate the object from edge caches. The next time a viewer requests the object, CloudFront returns to the origin to fetch the latest version of the object.

This will help you out.. http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html