Access ENV variables using Lua

class Fly
  def self.database_url
    primary = ENV["PRIMARY_REGION"]
    current = ENV["FLY_REGION"]
    db_url = ENV["DATABASE_URL"]

How can I achieve primary = ENV[“PRIMARY_REGION”] in Lua?
Means, how can I get environment variable values in Lua programming?

Hi @BalajiPothula I don’t have experience with Lua, but I’d assume the os.getenv method as described in Lua - Operating System Facilities should work.

Are you running a container with a Lua codebase on it, or would this be Lua inside the context of some other system like Redis? That would make a big difference, I imagine.

HI @sudhir.j
Thanks for the reply.

The scenario is Developing a simple web application (with user registration form) in html (front end), get user data using Lua (POST call) which is backend or middleware logic, then persist into the PostgreSQL.

Then in that case the

the os.getenv method as described in Lua - Operating System Facilities should work.

method should be what you need. You’d want to use the DATABASE_URL to connect the the DB. :+1: