Is it possible to alias or change the name of env that autopopulated for Postgres?

Hi :wave:,

I have a question regarding environment variables that automatically generated for postgres apps that attached to fly apps. ie:

fly pg attach --postgres-app chaos-postgres

From reading Multi-Region Databases it appears that running the above command will install these environment variables:

  • DATABASE_URL
  • PRIMARY_REGION
  • FLY_REGION

However, I can’t use these directly because I use config-rs I have to be explicit about the my configuration for my application. So I need to alias these environment variable to be:

  • APP_DATABASE__URL
  • APP_DATABASE__PRIMARY_REGION
  • APP_DATABASE__FLY_REGION

This will map to:

{
  ...
  "database": {
    "url": "xxx",
    "primary_region": "xxx",
    "fly_region": "xxx"
  }
}

Is it possible to alias the installed envs so that my application picks them up? Is it possible to do it via fly.toml?

1 Like

Hi there!

As far as I know, no, there’s no way to make fly export other environment variable names.

You have several options though:

  • You could choose to read these variables without config-rs
  • You could configure config-rs to read from the environment “unprefixed”, at least for these 3

If you find that a library is making it harder for you to do something pretty simple (reading some environment variables), then it’s probably getting in the way of your work more than helping you with it!

1 Like

You could also add an entrypoint to your Dockerfile and assign the env vars you want from the current ones.

export APP_DATABASE__URL = $DATABASE_URL
# ...
3 Likes