Skip to content

ExAws.Config.build_base() cannot get region when using configparser_ex #1144

@carloshanson-itrac

Description

@carloshanson-itrac

I would like to use {:awscli, profile, timeout} for all AWS config values.

config :ex_aws,
  access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, {:awscli, "profile", 30}],
  secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, {:awscli, "profile", 30}],
  region: [{:system, "AWS_REGION"}, {:awscli, "profile", 30}]

However, when using this method, I receive the following error:

iex(1)> ExAws.S3.list_objects("bucket-name") |> ExAws.request()
** (FunctionClauseError) no function clause matching in Regex.run/3    
    
    The following arguments were given to Regex.run/3:
    
        # 1
        ~r/^(us|eu|af|ap|sa|ca|me)\-\w+-\d?-?\w+$/
    
        # 2
        %{
          access_key_id: "ABCDEF...",
          secret_access_key: "abc123...",
          region: "us-west-2"
        }
    
        # 3
        []
    
    Attempted function clauses (showing 1 out of 1):
    
        def run(%Regex{} = regex, string, options) when is_binary(string)
    
    (elixir 1.18.4) lib/regex.ex:360: Regex.run/3
    (elixir 1.18.4) lib/enum.ex:4404: Enum.find_list/3
    (ex_aws 2.5.10) lib/ex_aws/config/defaults.ex:115: ExAws.Config.Defaults.host/2
    (ex_aws 2.5.10) lib/ex_aws/config/defaults.ex:110: ExAws.Config.Defaults.get/2
    (ex_aws 2.5.10) lib/ex_aws/config.ex:96: ExAws.Config.build_base/2
    (ex_aws 2.5.10) lib/ex_aws/config.ex:69: ExAws.Config.new/2
    (ex_aws 2.5.10) lib/ex_aws.ex:73: ExAws.request/2
    iex:1: (file)

Argument "# 2" above should be "us-west-2".

The problem is in ExAws.Config.build_base() when it tries to set region. The last function in the pipeline, ExAws.Config.retrieve_runtime_value(), can return a single value or a map.

region =
      (Map.get(overrides, :region) ||
         Map.get(service_config, :region) ||
         Map.get(common_config, :region) ||
         "us-east-1")
      |> retrieve_runtime_value(%{})

In the case of {:system, "AWS_REGION"}, it returns a single value, e.g. "us-east-1". When using :awscli, however, it returns the map seen in argument "# 2" above.

One solution would be to adjust the pipeline in ExAws.Config.build_base() to get the region from a map if that is what is returned or accept the single returned value.

Alternately, maybe we should specify and use the :awscli key, for example, {:awscli, "profile", 30, "region"}, so it can be pulled from the map that ExAws.Config.AuthCache.get() returns. We specify the environment variable name when using :system, so I'm unclear why we don't do that for :awscli too.

While there is no example in the documentation about using :awscli for region, it seems like it should be an option.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions