Scaleway is a French web hosting company, founded by Xavier Niel in 1999. It provides physical and online dedicated servers, domain registration services and datacenters.
In 2020, Scaleway was the second player in France behind OVHCloud and the third in Europe.
If you want an alternative to Amazon AWS S3 storage services, follow along this tiny and easy tutorial 😊
Scaleway part
Let’s begin with the Scaleway config 👨🏻🔧
1️⃣ First step: Create an account on Scaleway Elements:
👉🏻 https://www.scaleway.com/fr/object-storage/
2️⃣ Second step: Create your S3 bucket by going to your Scaleway console and “Object Storage” tab.
Here, a help procedure if needed:
👉🏻 https://www.scaleway.com/en/docs/object-storage-feature/#-Operation-Procedures
3️⃣ Third step: Generate your Access key and your Secret key 🔐 (do not forget to store them somewhere like 1Password or Bitwarden for example):
👉🏻 https://www.scaleway.com/en/docs/generate-api-keys/
Ruby On Rails part
The funniest part: integrating Scaleway into your Rails app 👩🏽💻
- After installing ActiveStorage and creating the active_storage_tables migration, you can add the “aws-sdk-s3” gem to your Gemfile
# Gemfile
gem 'aws-sdk-s3', require: false
- Then, you can add your credentials to your .env file (do not forget to add your file to your .gitignore)
# .env
SCALEWAY_ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID SCALEWAY_SECRET_ACCESS_KEY_ID=YOUR_SECRET_ACCESS_KEY_ID SCALEWAY_BUCKET_NAME=YOUR_BUCKET_NAME
- Add this config to you storage.yml with your personal keys and bucket
# storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>local:
service: Disk
root: <%= Rails.root.join("storage") %>scaleway:
service: S3
# Scaleway API endpoint, depending on your region
endpoint: https://s3.fr-par.scw.cloud
# Do not forget to hide your secrets
access_key_id: <%= ENV['SCALEWAY_ACCESS_KEY_ID'] %>
# Do not forget to hide your secrets
secret_access_key: <%= ENV['SCALEWAY_SECRET_ACCESS_KEY_ID'] %>
region: fr-par # Your bucket region, here it's Paris
bucket: <%= ENV['SCALEWAY_BUCKET_NAME'] %> # Your bucket name
- Do not forget to tell Rails to use Scaleway storage in production environment
# production.rb
config.active_storage.service = :scaleway
- Finally, you can attach your files to your records as usual 🙌🏻
# user.rb
has_one_attached :avatar# users_controller.rb
@user.avatar.attach(params[:avatar])
That’s it 🎉
👉 Check out the article on Dev.to : https://dev.to/fralps/configure-scaleway-s3-for-active-storage-in-rails-6-0-4n3n