2

I have an application which will be used only in India. I am using Cloudfront distribution to serve the assets. I already have versioning strategy implemented for changing the names of the assets which are changed for the build.

Given all that I only have to invalidate index.html which takes care of using versioned other assets.

I am using cloudfront invalidation to invalidate index.html . I have observed that invalidating this single file always takes more than 2 minutes. I understand its because its invalidating the file at 42 edge locations. I dont need the file to be placed and invalidated at 42 edge location. If there is any configuration which will keep the file only at the edge locations in India, I guess invalidations will be faster.

Is there any configuration like that to limit copying of file at specific edge locations.

2 Answers 2

6

Amazon CloudFront uses a pull model, so files are only cached in locations after they have been requested from a cache location.

For example:

  • A user on the Internet requests a file from your CloudFront distribution (eg dxxx.cloudfront.net/index.html)
  • The user is directed to the closest edge location (eg Chennai)
  • If the cache does not contain a copy of the file, then CloudFront fetches the file from the Origin (eg Amazon S3, an Amazon EC2 server, or elsewhere)
  • If the cache DOES contain a copy of the file, but it is past the expiration date, CloudFront will query the origin to determine whether the file has been modified since the last retrieval. If it has been modified, the updated file is fetched.
  • The file is then returned to the user.

It is not possible to instruct CloudFront to only store the file in a single edge location. The closest capability is the use of a Price Class.

From Amazon CloudFront pricing:

  • Price Class 100: USA, Europe
  • Price Class 200: USA, Europe, Hong Kong, Philippines, S. Korea, Singapore, Taiwan, Japan, India
  • Price Class All: USA, Europe, Hong Kong, Philippines, S. Korea, Singapore, Taiwan, Japan, India, South America, Australia

These price classes can be used to limit the locations from which Amazon CloudFront serves content, in order to reduce costs (eg South America and Australia have the highest Data Transfer cost per GB).

However, they cannot be used to instruct CloudFront to only store content in one location, nor to speed the Invalidation process.

3
  • Thanks for the detailed answer. I now have better idea of understanding of cloudfront. Can you guess why it might be taking time as high as 2 minutes to invalidate a single file. Is it in the queue waiting for its turn or something like that.
    – Vishwanath
    Jul 29, 2015 at 12:03
  • The documentation states "It usually takes 10 to 15 minutes for CloudFront to complete your invalidation request, depending on the number of invalidation paths that you included in the request." I could not find any information on 'why' it takes that long. Jul 29, 2015 at 12:16
  • Well, all I wanted was to invalidate one file. Later on found out that better way to do is to use cache-control: private so that file is not stored by cloudfront at all..
    – Vishwanath
    Aug 6, 2015 at 7:10
0

you can cache content based on request headers and with more granular control i.e based on geo-location. Amazon CloudFront adds additional geolocation headers for more granular geotargeting. Previously, you could configure Amazon CloudFront to provide the viewer’s country code in a request header that CloudFront sends to your origin. The new headers give you more granular control of cache behavior and your origin access to the viewer’s country name, region, city, postal code, latitude, and longitude, all based on the viewer’s IP address.

here is the link describing this - https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-cloudfront-headers.html#cloudfront-headers-viewer-location

You can use these additional geolocation headers along with the existing supported CloudFront headers to personalize the content that you deliver to your viewers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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