Reputation: 1140
I have over 5,000 html files that I want to save in S3 and serve it via cloudfront service. What is the proper way to make distributions to files?
Do you make one distribution for all files? Or distribution per file?
The reason I ask this question is that the files can be updated and as soon as they update, I want the cloud front to serve immediately the updated files.
So on one side, do a invalid to the distribution(the one that contain all the files) every time a single file from the 5,000 is updated ... I do not know if that's best practice. On the other side I do not know it also best practice to manage more than 7,000 cloudfront distributions
Also, how I can achieve it programatically with aws-skd or lamda (Push invalidation to the distribution)?
Upvotes: 0
Views: 158
Reputation: 270114
You should use a single distribution. It is rare that you would need more than one CloudFront distribution.
They key to providing files quickly is that they are cached in many locations around the world. This also means that invalidating a file is quite expensive in terms of effort, time and cost.
Cost: No additional charge for the first 1,000 paths requested for invalidation each month. Thereafter, $0.005 per path requested for invalidation.
You could instead have a low TTL so that the files are checked more often, but this also slows delivery of the files because the origin has to be checked more often. (Amazon CloudFront works on a pull model, rather than a push model.)
So, it's always a tradeoff between serving files quickly and having the ability to update/invalidate the cache.
Upvotes: 1