How to use System.get_env inside my config.exs file?

This way it works for me but the problem is that I expose the keys explicitly and the keys must be in my .env file

aws_access_key_iam_user = "access_key"
aws_secret_access_key_iam_user = "secret_key"

config :ex_aws,
  json_codec: Jason,
  access_key_id: aws_acces_key_iam_user,
  secret_access_key: aws_secret_acces_key_iam_user

When I save the keys in my .env file

config :ex_aws,
    json_codec: Jason,
    access_key_id: System.get_env("AWS_ACCESS_KEY_IAM_USER"),
    secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY_IAM_USER")

The SignatureDoesNotMatch error indicates that the signature generated to authenticate the request to AWS does not match what the service expects.

Dont read the environment in config.exs, that is only read at build time.

You want to use runtime.exs, which is evaluated on each application boot.

5 Likes