# AWS SDK - Ruby

## **What is AWS SDK - Ruby?**

AWS SDKs (software development kits) help simplify coding and application development by supporting and providing code objects for use with S3-compatible services. There are a variety of different AWS SDKs, each for a different coding language. This guide covers AWS SDK - Ruby.

{% hint style="success" %}

### Prerequisites:

* [x] [Download and install](https://www.ruby-lang.org/en/downloads/) Ruby in your environment.
* [x] [Download and install](https://github.com/aws/aws-sdk-ruby) the AWS SDK for Ruby.
* [x] [Sign up](https://filebase.com/signup) for a free Filebase account.&#x20;
* [x] Have your Filebase Access and Secret Keys. Learn how to view your access keys [here](https://docs.filebase.com/getting-started-guides/getting-started-guide#working-with-access-keys).
  {% endhint %}

{% hint style="danger" %}
This guide was written using Ubuntu 20.04 and tested using the command line interface. If you are using an Integrated Development Environment (IDE), the installation of dependencies and modules will vary.
{% endhint %}

### Create a Bucket

The following code example creates a new Filebase bucket. Replace the following values in the code to match your configuration:

* **filebase-access-key:** Your Filebase Access Key
* **filebase-secret-key:** Your Filebase Secret Key
* **new-filebase-bucket:** The Intended New Bucket Name

{% hint style="info" %}
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.&#x20;

Buckets created through this method will be automatically created on the IPFS networ&#x6B;*.*
{% endhint %}

```ruby
require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: 'filebase-access-key',
secret_access_key: 'filebase-secret-key',
region: 'us-east-1',
endpoint: 'https://s3.filebase.com'
)

bucket_name = 'filebase-bucket-name'
s3.create_bucket(bucket: bucket_name)
```

### Upload an Object

The following code example uploads an object to the specified bucket. Replace the following values in the code to match your configuration:

* **filebase-access-key:** Your Filebase Access Key
* **filebase-secret-key:** Your Filebase Secret Key
* **filebase-bucket-name:** The Filebase Bucket Name
* **/path/to/object/to/upload**: The file path to the object that you want to be uploaded
* **object-name**: The desired object name once uploaded

```ruby
require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: 'filebase-access-key',
secret_access_key: 'filebase-secret-key',
region: 'us-east-1',
endpoint: 'https://s3.filebase.com'
)

bucket_name = 'filebase-bucket-name'
object_key = 'object-name'
object_path = '/path/to/object/to/upload'

File.open(object_path, 'rb') do |file|
s3.put_object(bucket: bucket_name, key: object_key, body: file)
end
```

### Download an Object

The following code example downloads an object from the specified bucket. Replace the following values in the code to match your configuration:

* **filebase-access-key:** Your Filebase Access Key
* **filebase-secret-key:** Your Filebase Secret Key
* **filebase-bucket-name:** The Filebase Bucket Name
* **object-name**: The object to be downloaded

```ruby
require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: 'filebase-access-key',
secret_access_key: 'filebase-secret-key',
region: 'us-east-1',
endpoint: 'https://s3.filebase.com'
)

bucket_name = 'filebase-bucket-name'
object_key = 'object-name'

s3.get_object(bucket: bucket_name, key: object_key)
```

### Delete an Object

The following code example deletes an object from the specified bucket. Replace the following values in the code to match your configuration:

* **filebase-access-key:** Your Filebase Access Key
* **filebase-secret-key:** Your Filebase Secret Key
* **filebase-bucket-name:** The Filebase Bucket Name
* **object-name**: The object to be downloaded

```ruby
require 'aws-sdk-s3'

s3 = Aws::S3::Client.new(
access_key_id: 'filebase-access-key',
secret_access_key: 'filebase-secret-key',
region: 'us-east-1',
endpoint: 'https://s3.filebase.com'
)

bucket_name = 'filebase-bucket-name'
object_key = 'object-name'

s3.delete_object(bucket: bucket_name, key: object_key)
```
