Search code examples
herokuruby-on-rails-4amazon-s3cdnamazon-cloudfront

Where are my assets files stored?


As I have read, Heroku recommends pointing your CDN directly at your dynos rather than using asset_sync, therefore I did this:

# config/environments/production.rb
config.action_controller.asset_host = "<MY DISTRIBUTION SUBDOMAIN>.cloudfront.net"

The origin of my distribution is dcaclab.com The CNAMEs of my distribution is assets.dcaclab.com

So, after I successfully pushed my rails 4 app to heroku, I found that all my assets are served from my cloudfront's distribution, like:

http://<MY DISTRIBUTION SUBDOMAIN>.cloudfront.net/assets/features/Multiple%20Circuits-edbfca60b3a74e6e57943dc72745a98c.jpg

What I don't understand, is how my assets files got uploaded to the my cloudfront's distribution?! also, where I can find them? I thought they would be uploaded to my s3 bucket assets but it was just empty.

Can some enlighten me please?


Solution

  • If your files are being served from your CloudFront distribution and they are not being pulled from your S3 bucket "assets" as you previously thought, then you probably have set up your CloudFront distribution to use a custom origin such as your web server (S3 buckets are the normal/standard origins).

    If you have set up your CloudFront distribution to use your web server as the origin, then CloudFront will pull the files from your web server before caching them on different edge locations (the pulling and caching is automatically done by CloudFront when a user access resources through the "distributionname.cloudfront.net" domain).

    By the way, just a side note, I ran "dig assets.dcaclab.com" which resolves to "assets.dcaclab.com.s3.amazonaws.com".