View Source AWS.Client (aws-elixir v1.0.4)
Provides credentials and connection details for making requests to AWS services.
You can configure access_key_id
and secret_access_key
which are the credentials
needed by IAM, and also the region
for your services.
The list of regions can be found in the AWS service endpoints
documentation. You can also use "local" to make requests to your localhost.
custom-http-client
Custom HTTP client
The option http_client
accepts a tuple with a module and a list of options.
The module must implement the callback AWS.HTTPClient.request/5
.
custom-json-or-xml-parsers
Custom JSON or XML parsers
You can configure a custom JSON parser by using the option json_module
. This
option accepts a tuple with a module and options. The given module must
implement the callbacks from AWS.JSON
.
Similarly, there is a xml_module
option that configures the XML parser. The
XML module must implement the callbacks from AWS.XML
.
additional-options
Additional options
:session_token
- an option to set theX-Amz-Security-Token
when performing the requests.:port
- is the port to use when making requests. Defaults to443
.:proto
- is the protocol to use. It can be "http" or "https". Defaults to"https"
.:endpoint
- the AWS endpoint. Defaults to"amazonaws.com"
. You can configure this usingput_endpoint/2
for AWS compatible APIs.
The service
option is overwritten by each service with its signing name from metadata.
Link to this section Summary
Functions
The default endpoint.
Configures the endpoint to a custom one.
Configures the HTTP client used by a given client.
Makes a HTTP request using the specified client.
Link to this section Functions
The default endpoint.
Check put_endpoint/2
for more details on how to configure
a custom endpoint.
Configures the endpoint to a custom one.
This is useful to set a custom endpoint when working with AWS compatible APIs. The following configuration is valid:
"example.com"
: this will be used as it is, without considering regions or endpoint prefixes or account id.{:keep_prefixes, "example.com"}
: it will keep the same rules from AWS to build the prefixes. For example, if region is "us-east-1" and the service prefix is "s3", then the final endpoint will be"s3.us-east-1.example.com"
fn options -> "example.com" end
: a function that will be invoked with options for that request.options
is a map with the following shape:%{ endpoint: endpoint_config(), region: binary() | nil, service: binary(), global?: boolean(), endpoint_prefix: binary(), account_id: binary() | nil }
examples
Examples
iex> put_endpoint(%Client{}, "example.com")
%Client{endpoint: "example.com}
iex> put_endpoint(%Client{}, {:keep_prefixes, "example.com"})
%Client{endpoint: {:keep_prefixes, "example.com}}
iex> put_endpoint(%Client{}, fn opts -> Enum.join(["baz", opts.region, "foo.com"], ".") end)
%Client{endpoint: #Function<>}
Configures the HTTP client used by a given client.
Switches to a different HTTP client, defined by a {module, opts}
tuple. See
AWS.HTTPClient
behavior for more details.
examples
Examples
iex> AWS.Client.put_http_client(%AWS.Client{}, {MyHTTPClient, []})
%AWS.Client{http_client: {MyHTTPClient, []}}
iex> AWS.Client.put_http_client(%AWS.Client{}, {AWS.HTTPClient.Finch, finch_name: AWS.Finch})
%AWS.Client{http_client: {AWS.HTTPClient.Finch, finch_name: AWS.Finch}}
Makes a HTTP request using the specified client.
retries-and-options
Retries and options.
The option :enable_retries?
enables request retries on known errors such as 500s.
enable_retries?
- Defaults tofalse
.retry_opts
- the options to configure retries in case of errors. This uses exponential backoff with jitter.:max_retries
- the maximum number of retries (plus the initial request). Defaults to10
.:base_sleep_time
- the base sleep time in milliseconds. Defaults to5
.:cap_sleep_time
- the maximum sleep time between attempts. Defaults to5_000
.
See "FullJitter" at: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
examples
Examples
iex> AWS.Client.request(client, :post, url, payload, headers, options)
{:ok, %{status_code: 200, body: body}}
iex> AWS.Client.request(client, :post, url, payload, headers, enable_retries?: true)
{:ok, %{status_code: 200, body: body}}
iex> AWS.Client.request(client, :post, url, payload, headers, enable_retries?: true, retry_opts: [max_retries: 3])
{:ok, %{status_code: 200, body: body}}