Skip to content

Fix precedence in env provider#95

Merged
onno-vos-dev merged 1 commit intoaws-beam:masterfrom
brettbeatty:master
Feb 1, 2026
Merged

Fix precedence in env provider#95
onno-vos-dev merged 1 commit intoaws-beam:masterfrom
brettbeatty:master

Conversation

@brettbeatty
Copy link
Contributor

The README suggests Erlang application environment variables take precedence over OS environment variables, but the aws_credentials_env provider reverses that. This PR updates the provider to align with what's documented in the README.

What's documented

This is a library to retrieve AWS credentials from a variety of possible sources in the following default order:

  1. Erlang application environment variables
  2. OS environment variables
    ...

What's occurring

I'm coming from Elixir, so that's what I'm more familiar with.

In this script we set both system env vars and application config (Erlang env vars) for our credentials, and the aws_credentials_env provider gives us the credentials from the system env vars. Only when the system env vars are deleted does it fall back to the Erlang ones.

Mix.install(
  [aws_credentials: "~> 1.0.3"],
  config: [
    aws_credentials: [
      aws_access_key_id: ~c"erlang env key",
      aws_secret_access_key: ~c"erlang env secret"
    ]
  ],
  system_env: %{
    "AWS_ACCESS_KEY_ID" => "os env key",
    "AWS_SECRET_ACCESS_KEY" => "os env secret"
  }
)

:aws_credentials_env.fetch([])
# {:ok,
#  %{
#    access_key_id: "os env key",
#    credential_provider: :aws_credentials_env,
#    secret_access_key: "os env secret"
#  }, :infinity}

System.delete_env("AWS_ACCESS_KEY_ID")
System.delete_env("AWS_SECRET_ACCESS_KEY")

:aws_credentials_env.fetch([])
# {:ok,
#  %{
#    access_key_id: "erlang env key",
#    credential_provider: :aws_credentials_env,
#    secret_access_key: "erlang env secret"
#  }, :infinity}

AI disclosure

I let AI write the test for me, but it appears to be in line with the other tests.

The README suggests Erlang application environment variables take
precedence over OS environment variables, but the aws_credentials_env
provider reverses that. This PR updates the provider to align with
what's documented in the README.
@onno-vos-dev onno-vos-dev merged commit 99d0f0e into aws-beam:master Feb 1, 2026
6 checks passed
@onno-vos-dev
Copy link
Member

Tagged as 1.0.4 release to hex as well see: hex 1.0.4

Thank you for your contribution!

@brettbeatty
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants