-
Notifications
You must be signed in to change notification settings - Fork 520
/
ex_aws.ex
79 lines (62 loc) · 2.04 KB
/
ex_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
defmodule ExAws do
@moduledoc File.read!("#{__DIR__}/../README.md")
use Application
@doc """
Perform an AWS request
First build an operation from one of the services, and then pass it to this
function to perform it.
This function takes an optional second parameter of configuration overrides.
This is useful if you want to have certain configuration changed on a per
request basis.
## Examples
```
ExAws.S3.list_buckets |> ExAws.request
ExAws.S3.list_buckets |> ExAws.request(region: "eu-west-1")
ExAws.Dynamo.get_object("users", "foo@bar.com") |> ExAws.request
```
"""
@spec request(ExAws.Operation.t) :: term
@spec request(ExAws.Operation.t, Keyword.t) :: {:ok, term} | {:error, term}
def request(op, config_overrides \\ []) do
ExAws.Operation.perform(op, ExAws.Config.new(op.service, config_overrides))
end
@doc """
Perform an AWS request, raise if it fails.
Same as `request/1,2` except it will either return the successful response from
AWS or raise an exception.
"""
@spec request!(ExAws.Operation.t) :: term | no_return
@spec request!(ExAws.Operation.t, Keyword.t) :: term | no_return
def request!(op, config_overrides \\ []) do
case request(op, config_overrides) do
{:ok, result} ->
result
error ->
raise ExAws.Error, """
ExAws Request Error!
#{inspect error}
"""
end
end
@doc """
Return a stream for the AWS resource.
## Examples
```
ExAws.S3.list_objects("my-bucket") |> ExAws.stream!
```
"""
@spec stream!(ExAws.Operation.t) :: Enumerable.t
@spec stream!(ExAws.Operation.t, Keyword.t) :: Enumerable.t
def stream!(op, config_overrides \\ []) do
ExAws.Operation.stream!(op, ExAws.Config.new(op.service, config_overrides))
end
@doc false
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(ExAws.Config.AuthCache, [[name: ExAws.Config.AuthCache]])
]
opts = [strategy: :one_for_one, name: ExAws.Supervisor]
Supervisor.start_link(children, opts)
end
end