backin
backin

Reputation: 21

Issue setting AWS ECS environment variables in runtime.exs with Elixir

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.

Upvotes: 0

Views: 37

Answers (1)

backin
backin

Reputation: 21

This is my .tfvars file

vars_by_workspace = {
  qa = {
     ecs_web_app_config = {}
     map_container_environment = {
        POOL_SIZE = "10"
        SENDGRID_API_KEY = ""
        ENVIRONMENT = "Stage"
        ...
       }

    secrets = [...]
    }
  }
  prod = {
     ecs_web_app_config = {]
     map_container_environment = {
        POOL_SIZE = "10"
        SENDGRID_API_KEY = ""
        ENVIRONMENT = "Prod"
        ...
       }

    secrets = [...]
    }
  }

Upvotes: 0

Related Questions