Active Storage, AWS S3 and Cloudfront
Im trying to setup cloudfront for my aws s3 storage of user uploaded images. Not sure what settings to change in the storage.yml file to point to the cloudfront and still work with everything else. Would it be just changing the endpoint variable to the cloudfront url?
Cloudfront would actually be setup in the console or cli, terraform etc.. which would then cache content from your s3 bucket at edge locations. As far as your storage.yml, you just use s3 like normal. Any files uploaded through the app would then get picked up by cloudfront automatically (although new assets won't get cached until the edge location gets a request for that asset).
As far as linking, use your cloudfront distribution url that you got when you set it up and AWS will take care of routing to the closest edge location for you.
Hope that helps.
Ok, ill give it a shot. So shouldnt need to change anything in my code and just set up the cloudfront in AWS
Not for storage.yml. If you want to link to any of those assets though, you'll need to use the cf distribution domain in the link.
Sorry Alex, I think I initially misunderstood what you were trying to do but now I think I understand. I did some quick research and it doesn't look like there is any "out of the box" support for cloudfront in active storage atm. I did find a gist that might help you though, assuming you haven't tried it already. I'll do some further looking as well and see if there might not be a better solution. Gist url is https://gist.github.com/timm-oh/10c4f06effa536ff32c5d038e0dd57e1
I'm looking to add CloudFront for Uploads of new files only to help speed up uploads to S3. AWS docs say to use Amazon CloudFront's PUT/POST to do this for files under 1GB in size. I use CloudFLARE for my CDN etc on my app.
So I'm trying to figure out how I would configure CloudFront for uploads only, and set up my Rails app using Active storage for that.
Any thoughts on that?