Issue setting AWS ECS environment variables in runtime.exs

I’m working on a project in Elixir that runs in a container deployed on AWS ECS. I’m trying to use environment variables to define the execution environment (ENVIRONMENT) and access them within my application.

Configuration
In my runtime.exs file, I am configuring like this:

if config_env() in [:prod, :stage] do
  environment = System.get_env("ENVIRONMENT") || "Devs"

  config :lxp, :aws_config,
    environment: environment
end

Then, I have the following module in my code:

defmodule Lxp.AwsConfig do
  def get_environment do
    Application.get_env(:lxp, :aws_config)[:environment] || "Devs"
  end
end

I understand that the get_environment function always returns “Devs”, which indicates that the ENVIRONMENT environment variable is not being read correctly from the container.

1 Like