Setting Up S3 CDN

This is a premium course, which you can purchase below.

Buy Now

We don't want our CMS images served from our disk in production, so we need to set up a CDN. I'll use S3 as that's what I know.


Setting up S3 is a matter of uncommenting some settings in your config/storage.yml file:

amazon:
  service: S3
  access_key_id: <%=ENV.fetch("AWS_ACCESS_KEY_ID")%>
  secret_access_key: <%= ENV.fetch("AWS_SECRET_ACCESS_KEY") %>
  region: us-west-1
  bucket: bigrails
  public: true

You then need to set config/environments/production.rb to use the amazon provider:

config.active_storage.service = :amazon