|
| 1 | +# ExAWS Elixir SDK |
| 2 | + |
| 3 | +import CodeBlock from "@theme/CodeBlock"; |
| 4 | + |
| 5 | +This guide assumes that you have followed the steps in the |
| 6 | +[Getting Started](/docs/get-started/index.md) guide, and have the access keys |
| 7 | +available. |
| 8 | + |
| 9 | +You may continue to use the ExAWS SDK as you normally would, but with the |
| 10 | +endpoint set to `https://fly.storage.tigris.dev`. |
| 11 | + |
| 12 | +This example reads the credentials from the environment variables |
| 13 | +`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. |
| 14 | + |
| 15 | +## ExAWS configuration |
| 16 | + |
| 17 | +### Dependencies |
| 18 | + |
| 19 | +Add the dependencies to your `mix.exs` file: |
| 20 | + |
| 21 | +```elixir |
| 22 | + defp deps do |
| 23 | + [ |
| 24 | + {:ex_aws, "~> 2.0"}, |
| 25 | + {:ex_aws_s3, "~> 2.0"}, |
| 26 | + {:poison, "~> 3.0"}, |
| 27 | + {:hackney, "~> 1.9"}, |
| 28 | + {:sweet_xml, "~> 0.6.6"}, |
| 29 | + {:jason, "~> 1.1"}, |
| 30 | + ] |
| 31 | + end |
| 32 | +``` |
| 33 | + |
| 34 | +### Development configuration |
| 35 | + |
| 36 | +Now setup the configuration for ex_aws and ex_aws_s3 in your `dev.exs` file (or |
| 37 | +`config/config.exs` file): |
| 38 | + |
| 39 | +import configEXS from "!!raw-loader!../../../examples/elixir/config/config.exs"; |
| 40 | + |
| 41 | +<CodeBlock language="elixir">{configEXS}</CodeBlock> |
| 42 | + |
| 43 | +In the first config we configure :ex_aws, by setting the access_key_id and |
| 44 | +secret_access_key. In this case we use AWS_ACCESS_KEY_ID and |
| 45 | +AWS_SECRET_ACCESS_KEY environment variables to store the access keys we will use |
| 46 | +to access Tigris. |
| 47 | + |
| 48 | +Then we configure the S3 API endpoint, which is "fly.storage.tigris.dev". |
| 49 | + |
| 50 | +### Runtime configuration |
| 51 | + |
| 52 | +Now similar to above, let's add the configuration in `runtime.exs` file: |
| 53 | + |
| 54 | +```elixir |
| 55 | +import Config |
| 56 | + |
| 57 | +if config_env() == :prod do |
| 58 | + |
| 59 | + # .... |
| 60 | + # Configure S3 client for access to Tigris |
| 61 | + config :ex_aws, |
| 62 | + debug_requests: true, |
| 63 | + json_codec: Jason, |
| 64 | + access_key_id: {:system, "AWS_ACCESS_KEY_ID"}, |
| 65 | + secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"} |
| 66 | + |
| 67 | + config :ex_aws, :s3, |
| 68 | + scheme: "https://", |
| 69 | + host: "fly.storage.tigris.dev", |
| 70 | + region: "auto" |
| 71 | + |
| 72 | +end |
| 73 | +``` |
| 74 | + |
| 75 | +## Example |
| 76 | + |
| 77 | +import gettingStarted from "!!raw-loader!../../../examples/elixir/examples/getting_started.ex"; |
| 78 | + |
| 79 | +<CodeBlock language="elixir">{gettingStarted}</CodeBlock> |
| 80 | + |
| 81 | +## Using presigned URLs |
| 82 | + |
| 83 | +Presigned URLs can be used with the ExAWS SDK as follows: |
| 84 | + |
| 85 | +import presignedUrls from "!!raw-loader!../../../examples/elixir/examples/presigned_urls.ex"; |
| 86 | + |
| 87 | +<CodeBlock language="elixir">{presignedUrls}</CodeBlock> |
0 commit comments