Skip to content

Commit 3e6e9ab

Browse files
authored
Merge pull request #160 from tigrisdata/Xe/TIG-3546
Add Elixir examples
2 parents c115b9a + 167c5fe commit 3e6e9ab

16 files changed

+329
-255
lines changed

docs/sdks/s3/aws-elixir-sdk.md

Lines changed: 0 additions & 255 deletions
This file was deleted.

docs/sdks/s3/aws-elixir-sdk.mdx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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>

examples/elixir/.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

examples/elixir/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# If the VM crashes, it generates a dump, let's ignore it too.
14+
erl_crash.dump
15+
16+
# Also ignore archive artifacts (built via "mix archive.build").
17+
*.ez
18+
19+
# Ignore package tarball (built via "mix hex.build").
20+
tigrisexample-*.tar
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/

examples/elixir/bar.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hi there

examples/elixir/config/config.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Config
2+
3+
# Configure S3 client for access to Tigris
4+
config :ex_aws,
5+
debug_requests: true,
6+
json_codec: Jason,
7+
access_key_id: {:system, "AWS_ACCESS_KEY_ID"},
8+
secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}
9+
10+
config :ex_aws, :s3,
11+
scheme: "https://",
12+
host: "fly.storage.tigris.dev",
13+
region: "auto"

0 commit comments

Comments
 (0)