View Source AWS.Client (aws-elixir v0.14.1)

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

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

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

  • :session_token - an option to set the X-Amz-Security-Token when performing the requests.
  • :port - is the port to use when making requests. Defaults to 443.
  • :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 using put_endpoint/2 for AWS compatible APIs.

The service option is overwritten by each service with its signing name from metadata.

Summary

Types

The endpoint configuration.

t()

Types

@type endpoint_config() ::
  binary() | {:keep_prefixes, binary()} | (map() -> binary()) | nil

The endpoint configuration.

Check put_endpoint/2 for more details.

@type t() :: %AWS.Client{
  access_key_id: binary() | nil,
  endpoint: endpoint_config(),
  http_client: {module(), keyword()},
  json_module: {module(), keyword()},
  port: non_neg_integer(),
  proto: binary(),
  region: binary() | nil,
  secret_access_key: binary() | nil,
  service: binary() | nil,
  session_token: binary() | nil,
  xml_module: {module(), keyword()}
}

Functions

Link to this function

create(access_key_id, secret_access_key, region)

View Source
Link to this function

create(access_key_id, secret_access_key, token, region)

View Source
Link to this function

decode!(client, payload, format)

View Source

The default endpoint.

Check put_endpoint/2 for more details on how to configure a custom endpoint.

Link to this function

encode!(client, payload, format)

View Source
Link to this function

put_endpoint(client, endpoint_config)

View Source

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

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<>}
Link to this function

put_http_client(client, http_client)

View Source

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

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}}
Link to this function

request(client, method, url, body, headers, opts \\ [])

View Source