Skip to main content

AWS Ruby SDK

This guide assumes that you have followed the steps in the Getting Started guide, and have the access keys available.

You may continue to use the AWS Ruby SDK as you normally would, but with the endpoint set to https://fly.storage.tigris.dev. Also make sure force_path_style is set to false:

s3 = Aws::S3::Client.new(
region: "auto",
endpoint: "https://fly.storage.tigris.dev",
force_path_style: false,
)

This example uses the AWS Ruby SDK v3 and reads the default credentials file or the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

# frozen_string_literal: true

source "https://rubygems.org"

gem 'nokogiri', '~> 1.11'
gem 'aws-sdk-s3', '~> 1'

Then you can use the SDK as you normally would, but with the endpoint set to https://fly.storage.tigris.dev.

require "aws-sdk-s3"

bucket_name = "tigris-example"

s3 = Aws::S3::Client.new(
region: "auto",
endpoint: "https://fly.storage.tigris.dev",
)

# Lists all of your buckets
resp = s3.list_buckets
puts "My buckets now are:\n\n"

resp.buckets.each do |bucket|
puts bucket.name
end

# List the first ten objects in the bucket
resp = s3.list_objects(bucket: bucket_name, max_keys: 10)
resp.contents.each do |object|
puts "#{object.key} => #{object.etag}"
end

# Put an object into the bucket
file_name = "bar-file-#{Time.now.to_i}"
begin
s3.put_object(
bucket: bucket_name,
key: file_name,
body: File.read("getting_started.rb")
)
puts "Uploaded #{file_name} to #{bucket_name}."
rescue Exception => e
puts "Failed to upload #{file_name} with error: #{e.message}"
exit "Please fix error with file upload before continuing."
end

Presigned URLs

Presigned URLs are supported by the AWS Ruby SDK. You can generate a presigned URL by calling the presigned_url method on a Bucket object.

require "aws-sdk-s3"

s3 = Aws::S3::Client.new(
region: "auto",
endpoint: "https://fly.storage.tigris.dev",
force_path_style: false,
)

bucket_name = "tigris-example"
bucket = Aws::S3::Bucket.new(name: bucket_name, client: s3)

presigned_url = bucket.object("test-object").presigned_url(:get, expires_in: 3600)
puts "Presigned URL for GET: #{presigned_url}"