Environment variables
Server configuration
| Variable | Required | Default | Description |
|---|---|---|---|
PORT | No | 8080 | Port the server listens on |
Database configuration
| Variable | Required | Default | Description |
|---|---|---|---|
RDS_USERNAME | Yes | - | PostgreSQL username |
RDS_PASSWORD | Yes | - | PostgreSQL password |
RDS_HOSTNAME | Yes | - | PostgreSQL hostname (e.g., localhost or RDS endpoint) |
RDS_PORT | Yes | - | PostgreSQL port (usually 5432) |
RDS_DBNAME | Yes | - | PostgreSQL database name |
External services
| Variable | Required | Default | Description |
|---|---|---|---|
GOOGLE_GEOCODING_API_KEY | No* | - | Google Geocoding API key |
Configuration by environment
Local development
Create a.env file in the project root:
Staging
Staging environment variables are managed through:- AWS Secrets Manager:
staging-address-api-secrets - Terraform: Injected as ECS task environment variables
Production
Production environment variables are managed through:- AWS Secrets Manager:
prod-address-api-secrets - Terraform: Injected as ECS task environment variables
Database connection string
The application constructs the PostgreSQL connection string from environment variables:Connection pool configuration
The application uses the following connection pool settings (configured inconfigs/postgres.config.go):
| Setting | Value | Description |
|---|---|---|
MaxConns | 48 | Maximum number of connections |
MinConns | 12 | Minimum number of idle connections |
MaxConnLifetime | 30 minutes | Maximum connection lifetime |
MaxConnIdleTime | 5 minutes | Maximum idle time before closing |
HealthCheckPeriod | 30 seconds | Health check interval |
ConnectTimeout | 10 seconds | Connection establishment timeout |
Database-level timeouts
| Setting | Value | Description |
|---|---|---|
statement_timeout | 10 seconds | Maximum query execution time |
idle_in_transaction_session_timeout | 60 seconds | Maximum idle time in transaction |
lock_timeout | 2 seconds | Maximum time waiting for locks |
Validation
The application validates required environment variables on startup. If any required variable is missing, the server will fail to start with an error message:Security best practices
Local development
- Never commit
.envfiles: The.envfile is in.gitignore - Use strong passwords: Even for local development
- Rotate API keys: Regularly update your Google API key
Production
- Use AWS Secrets Manager: Never hardcode secrets in code or Terraform
- Enable secret rotation: Set up automatic rotation for database passwords
- Restrict IAM access: Only allow necessary services to read secrets
- Audit secret access: Monitor CloudWatch logs for secret access
Updating secrets
Local
Edit your.env file and restart the server:
Staging/Production
Update secrets in AWS Secrets Manager:Testing configuration
For integration tests, use.env.test.example as a template:
Troubleshooting
Error: “missing required environment variables”
Cause: One or more required variables are not set. Fix: Check the error message for which variables are missing and add them to your.env file.
Error: “could not ping the database”
Cause: Database connection failed. Fix:- Verify PostgreSQL is running
- Check connection details in
.env - Test connection manually:
Error: “Geocoding failed”
Cause: Google API key is missing or invalid. Fix:- Verify
GOOGLE_GEOCODING_API_KEYis set - Check the key is valid in Google Cloud Console
- Ensure the Geocoding API is enabled for your project