Serving tar.gz file through AWS Cloudfront?

0

I would like to keep things tidy on the S3 bucket where my website's assets live.

Currently I am uploading all assets to S3, as part of the CI/CD pipeline, this has got a bit messy since generated files don't always have the same name, so I now have lots of stale files. A quick fix would be to empty the s3 bucket before each new release but I have been thinking about something different.

Running this command I can generate one file out of my dist folder:

tar -zcvf MyWebApp.tar.gz dist

Is it possible to upload only this tar.gz file to my S3 bucket, so it is replaced on each new release, and have it served through cloudfront?

randomguy04

Posted 2019-06-28T09:46:29.543

Reputation: 101

I don't understand what you want to achieve here. It's normal for asset pipelines to generate unique asset files (with hashed names) that can be left on the asset server until they're expired. In principle, if you generate new assets, you can always throw out the old ones. The asset pipeline should not create new names for unchanged content, so that clients can continue using cached content. I'd recommend not serving one big asset file – that completely defeats the purpose of serving individually cachable files. – slhck – 2019-06-28T09:50:50.830

Caching is a very important thing indeed, what I am after is, learning if Cloudfront is capable of being fed a tar.gz, retrieve the files inside of it and serve + cache them properly – randomguy04 – 2019-06-28T09:57:37.337

I see, no, that's not possible. You have to have the correct file layout in S3 and point CloudFront to it. – slhck – 2019-06-28T10:16:25.053

Answers

0

CloudFront cannot do what you want. You have to serve individual files; CloudFront will just take a request and serve the file from S3. It does not offer you to untar anything.

It's normal for asset pipelines to generate unique asset files (with hashed names) that can be left on the asset server until they're expired. In principle, if you generate new assets, you can always throw out the old ones. The asset pipeline should not create new names for unchanged content, so that clients can continue using cached content.

So, in summary, if you update assets, you should actively remove the ones no longer needed from S3.

slhck

Posted 2019-06-28T09:46:29.543

Reputation: 182 472