0

I deploy a single-page application website by pushing assets to AWS S3 and serving the files through CloudFront. As per this answer, it isn't possible for me to serve files directly from S3 using SSL under my own domain, so I don't have a choice about using CloudFront if I want to serve files in this way.

When I redeploy, I generate a new timestamped, root HTML file (which itself links to the updated JS and CSS bundles), push it to S3 along with everything else, and then make that new file the new Default Root Object for the CloudFront distribution via the AWS. This prevents CloudFront from caching everything and hiding the updates.

The problem is that, occasionally, CloudFront takes a long time to update the root object. As I write this, I'm tabbing over hitting refresh every 60 seconds waiting for an important change to hit production. CloudFront shows the correct (newest) root object via the web console but it also shows "Status: In Progress."

At times, this delay is barely noticeable, and other times it's quite long. Today it is approaching an hour delay.

How can I avoid this? I'm open to both changes to this deployment method using S3 and CloudFront OR switching to an alternative platform that is known to handle this use case better.

Greg Sherrid
  • 38
  • 1
  • 5

1 Answers1

0

This is how I solved it.

Enable caching values to 0 seconds in cloud front. I have also noticed browser caches document served.

I had to add http headers to S3 bucket to serve every object not to cache,

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

Documentation on Object Expiration:

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html

If you set your cache to a long time and like to remove the cache from CloudFront, you can do the invalidation on the root object.

Hope it helps.

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83