Secrets not getting deployed

I ran fly deploy command after adding new secrets.
In phoenix app, i am accessing secrets in config.exs file.
To check they are available in app. I entered into iex shell after fly ssh console and ran System.get_env(“AWS_ACCESS_KEY_ID”) which returns correct value.
But when i run Application.get_env(:ex_aws, :access_key_id), it still returns nil.
Here is code in my config.exs

config :ex_aws, access_key_id: System.get_env("AWS_ACCESS_KEY_ID")

I don’t want to move them to runtime.exs files because I need env vars in module body so I have to use Application.compile_env/2

According to fly docs it should work but it is not.

Hi, could you link the name of your app, so I can take a further look?

It seems like you’re running into the difference between config options being available at compile time and runtime.

Since you’ve put that line in config.exs the AWS_ACCESS_KEY_ID env variable must be set at compile time.

Here’s how you can set build time secrets: Build Secrets · Fly Docs

1 Like

You most likely don’t need them at build/compile time, and you instead should read and set them in your config/runtime.exs file, which will read them at runtime at startup where they’ll be available.

1 Like

Thanks for taking a look at it.
Yup I am moving them to runtime.exs because it is most good fit solution on fly because it reads secrets at runtime.
Actually I was accessing env vars in Module body (not in function) where i had to read them at compile time.
Now I have moved them within function to use Application.get_env/2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.