Wednesday, 9 July 2025

Use .env File as a Local Substitute for Parameter Store

This is the simplest and most common approach for local development:

Idea:

  • If running locally, load config from .env

  • If running in production/staging, fetch from AWS Parameter Store

Example

import ( "os" ) // Load parameter based on environment func getParameter(name string) string { if os.Getenv("ENV") == "local" { // Load from .env or environment variable return os.Getenv(name) } // In non-local environments, load from AWS SSM val, err := getFromSSM(name) // implement this function if err != nil { panic(err) } return val }

Your .env file would look like:

ENV=local CLIENT_ID_BURTON=abc123 CLIENT_SECRET_BURTON=xyz456

Use github.com/joho/godotenv to load it

godotenv.Load()

No comments:

Post a Comment

Golang Advanced Interview Q&A