# ExAWS Elixir SDK

<!-- -->

This guide assumes that you have followed the steps in the [Getting Started](/docs/get-started/.md) guide, and have the access keys available.

You may continue to use the ExAWS SDK as you normally would, but with the endpoint set to Tigris at <https://t3.storage.dev>.

This example reads the credentials from the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.

## ExAWS configuration[​](#exaws-configuration "Direct link to ExAWS configuration")

### Dependencies[​](#dependencies "Direct link to Dependencies")

Add the dependencies to your `mix.exs` file:

```
  defp deps do

    [

      {:ex_aws, "~> 2.0"},

      {:ex_aws_s3, "~> 2.0"},

      {:poison, "~> 3.0"},

      {:hackney, "~> 1.9"},

      {:sweet_xml, "~> 0.6.6"},

      {:jason, "~> 1.1"},

    ]

  end
```

### Development configuration[​](#development-configuration "Direct link to Development configuration")

Now setup the configuration for ex\_aws and ex\_aws\_s3 in your `dev.exs` file (or `config/config.exs` file):

<!-- -->

```
import Config



# Configure S3 client for access to Tigris

config :ex_aws,

  debug_requests: true,

  json_codec: Jason,

  access_key_id: {:system, "AWS_ACCESS_KEY_ID"},

  secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}



config :ex_aws, :s3,

  scheme: "https://",

  host: "t3.storage.dev",

  region: "auto"
```

In the first config we configure <!-- -->:ex\_aws<!-- -->, by setting the access\_key\_id and secret\_access\_key. In this case we use AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY environment variables to store the access keys we will use to access Tigris.

Then we configure the S3 API endpoint, which is "t3.storage.dev".

### Runtime configuration[​](#runtime-configuration "Direct link to Runtime configuration")

Now similar to above, let's add the configuration in `runtime.exs` file:

```
import Config



if config_env() == :prod do



  # ....

  # Configure S3 client for access to Tigris

  config :ex_aws,

    debug_requests: true,

    json_codec: Jason,

    access_key_id: {:system, "AWS_ACCESS_KEY_ID"},

    secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}



  config :ex_aws, :s3,

    scheme: "https://",

    host: "t3.storage.dev",

    region: "auto"



end
```

## Example[​](#example "Direct link to Example")

<!-- -->

```
# List all buckets

all_buckets = ExAws.S3.list_buckets() |> ExAws.request!()



IO.puts("Buckets:")



for bucket <- all_buckets.body.buckets do

  IO.puts(bucket.name)

end



# List all objects in bucket tigris-example

bucket_name = "tigris-example"

all_objects = ExAws.S3.list_objects(bucket_name) |> ExAws.request!() |> get_in([:body, :contents])



IO.puts("Objects:")



for object <- all_objects do

  IO.puts(object.key)

end



# Put bar.txt

key = "bar.txt"

body = "Hello, world!"



response = ExAws.S3.put_object(bucket_name, key, body) |> ExAws.request!()

assert response.status_code == 200



# Read back bar.txt

response = ExAws.S3.get_object(bucket_name, key) |> ExAws.request!()

assert response.status_code == 200

assert response.body == body
```

## Using presigned URLs[​](#using-presigned-urls "Direct link to Using presigned URLs")

Presigned URLs can be used with the ExAWS SDK as follows:

<!-- -->

```
bucket_name = "tigris-example"

key = "bar_ex.txt"



{:ok, presigned_url} =

  ExAws.Config.new(:s3) |> ExAws.S3.presigned_url(:get, bucket_name, key, expires_in: 300)



IO.puts("Presigned URL for GET:")

IO.puts(presigned_url)



{:ok, presigned_url} =

  ExAws.Config.new(:s3) |> ExAws.S3.presigned_url(:put, bucket_name, key, expires_in: 300)



IO.puts("Presigned URL for PUT:")

IO.puts(presigned_url)
```

### Presigned URLs with custom domains[​](#presigned-urls-with-custom-domains "Direct link to Presigned URLs with custom domains")

You can also use a [presigned URL with a custom domain](/docs/objects/presigned/.md#presigned-url-with-custom-domain) by replacing the bucket host with your custom domain:

```
branded_url = String.replace(

  presigned_url, "foo-bucket.t3.storage.dev", "your-domain.example.com")

IO.puts("Presigned URL for GET (custom domain): #{branded_url}")
```
