-
Notifications
You must be signed in to change notification settings - Fork 133
/
aws.ex
48 lines (34 loc) · 1.9 KB
/
aws.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
defmodule AWS do
@moduledoc """
AWS provides an API to talk with Amazon Web Services.
Each module in this project corresponds with an AWS service,
and they can be used by calling the functions of those
modules. For example, "AWS DynamoDB" operations can be found
in `AWS.DynamoDB` module.
First we need to setup a `AWS.Client` structure with credentials
and details about the region we want to use.
client = %AWS.Client{
access_key_id: "<access-key-id>",
secret_access_key: "<secret-access-key>",
region: "us-east-1"
}
Alternatively you can create a `client` with `AWS.Client.create/3`.
Check more options for configuration at `AWS.Client` docs.
So we pass this client struct to our service modules:
{:ok, result, _http_response} = AWS.Kinesis.list_streams(client, %{})
The second argument in this case is the `input` which is a map with
the parameters for [this operation](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListStreams.html).
Another example is the upload of a given file to `AWS.S3` using `AWS.S3.put_object/5`:
client = AWS.Client.create("your-access-key-id", "your-secret-access-key", "us-east-1")
file = File.read!("./tmp/your-file.txt")
md5 = :crypto.hash(:md5, file) |> Base.encode64()
AWS.S3.put_object(client, "your-bucket-name", "foo/your-file-on-s3.txt", %{"Body" => file, "ContentMD5" => md5})
You can find more details about those parameters in the [AWS API reference](https://docs.aws.amazon.com/index.html).
## Custom HTTP client and JSON/XML parsers
You can customize your HTTP client or the module responsible for parsing
and encoding JSON or XML by using options for the `AWS.Client`.
By default, AWS Elixir uses hackney for the HTTP client, Jason for JSON,
and a custom module for XML that is written on top of xmlerl.
For more details, check `AWS.Client` documentation.
"""
end