Dwight Watson's blog

S3 Transfer Acceleration with Rails ActiveStorage

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

I've known about Amazon S3 Transfer Acceleration for a while but haven't had a good use-case. In brief, this feature allows you to speed up direct user uploads to an S3 bucket even if they're further away from a bucket's geographic location. It turns out that using Transfer Acceleration is 50% faster when uploading from Sydney, Australia to an S3 bucket in us-east-1.

Rails ActiveStorage supports direct file uploads to S3 - which means your users browser will upload directly to S3 and then confirm the asset with your Rails app. This makes Rails apps a perfect use-case for Transfer Acceleration. In addition, it's also a cinch to configure. After you're enabled Transfer Acceleration on your bucket, just add the use_accelerate_endpoint configuration.

service: S3
access_key_id: <%= Rails.application.secrets.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.secrets.dig(:aws, :secret_access_key) %>
region: us-east-1
bucket: <%= Rails.application.secrets.dig(:aws, :bucket) %>
use_accelerate_endpoint: true

Rails will just pass this additional arugment to the S3 Ruby client and the rest is handled for you - it will upload to the accelerate endpoint and deliver faster uploads to your users.

A blog about Laravel & Rails by Dwight Watson;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.