Using multiple buckets with ActiveStorage Using multiple buckets with ActiveStorage ruby-on-rails ruby-on-rails

Using multiple buckets with ActiveStorage


Although there isn't a way to use specific "buckets", one can pretty easily add multiple active storage configurations for multiple buckets (I believe introduced in v6.1):

https://edgeguides.rubyonrails.org/active_storage_overview.html#attaching-files-to-records

For example, you might have a "amazon_s3_cold" and an "amazon_s3_hot", they will have all the same configurations aside from the bucket. You may then configure your buckets accordingly on AWS.

# config/storage.ymlamazon_s3_hot:   service: S3   access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>   secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>   region: us-east-1   bucket: my_hot_bucketamazon_s3_cold:   service: S3   access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>   secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>   region: us-east-1   bucket: my_cold_bucket# controllersclass User < ApplicationRecord    has_one_attached :avatar, service: :amazon_s3_hotendclass DocumentRecord < ApplicationRecord    has_one_attached :document_upload, service: :amazon_s3_coldend

Note - hot/cold doesn't apply to the question directly, but provides some context. Hot/cold storage is a concept pertaining to cloud storage services that trades off costs for access frequencies.


There isn’t, sorry. Active Storage is designed for use with a single bucket.