Skip to content

Commit

Permalink
derive host from region
Browse files Browse the repository at this point in the history
  • Loading branch information
benwilson512 committed Oct 16, 2015
1 parent b3e4b03 commit d68ae5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/ex_aws/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule ExAws.Config do
config = client
|> ExAws.Config.get
|> Map.merge(Enum.into(opts, %{}))
|> parse_host_for_region

%{client | config: config}
|> retrieve_runtime_config
Expand Down Expand Up @@ -62,4 +63,15 @@ defmodule ExAws.Config do
end
def retrieve_runtime_value(value, _), do: value

def parse_host_for_region(%{host: {stub, host}, region: region} = config) do
%{config | host: String.replace(host, stub, region)}
end
def parse_host_for_region(%{host: map, region: region} = config) when is_map(map) do
case Map.fetch(map, region) do
{:ok, host} -> %{config | host: host}
:error -> "A host for region #{region} was not found in host map #{inspect(map)}"
end
end
def parse_host_for_region(config), do: config

end
20 changes: 15 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,40 @@ defmodule ExAws.Mixfile do
json_codec: Poison,
kinesis: [
scheme: "https://",
host: "kinesis.us-east-1.amazonaws.com",
host: {"$region", "kinesis.$region.amazonaws.com"},
region: "us-east-1",
port: 80
],
dynamodb: [
scheme: "https://",
host: "dynamodb.us-east-1.amazonaws.com",
host: {"$region", "dynamodb.$region.amazonaws.com"},
region: "us-east-1",
port: 80
],
lambda: [
host: "lambda.us-east-1.amazonaws.com",
host: {"$region", "lambda.$region.amazonaws.com"},
scheme: "https://",
region: "us-east-1",
port: 80
],
s3: [
scheme: "https://",
host: "s3.amazonaws.com",
host: %{
"us-east-1" => "s3.amazonaws.com",
"us-west-1" => "s3-us-west-1.amazonaws.com",
"us-west-2" => "s3-us-west-2.amazonaws.com",
"eu-west-1" => "s3-eu-west-1.amazonaws.com",
"eu-central-1" => "s3-eu-central-1.amazonaws.com",
"ap-southeast-1" => "s3-ap-southeast-1.amazonaws.com",
"ap-southeast-2" => "s3-ap-southeast-2.amazonaws.com",
"ap-northeast-1" => "s3-ap-southeast-1.amazonaws.com",
"sa-east-1" => "s3-sa-east-1.amazonaws.com",
},
region: "us-east-1"
],
sqs: [
scheme: "https://",
host: "sqs.us-east-1.amazonaws.com",
host: {"$region", "sqs.$region.amazonaws.com"},
region: "us-east-1"
]
]
Expand Down

0 comments on commit d68ae5f

Please sign in to comment.