06 Lambda Environment
DodaTech
1 min read
title: Lambda Environment Configuration for Serverless APIs weight: 16 date: 2026-06-28 lastmod: 2026-06-28 description: Configure Lambda environment variables for serverless APIs including secrets management, environment-specific config, encryption with KMS, and best practices. tags: [api-development, serverless]
Lambda environment variables store configuration like database URLs, API keys, and feature flags, supporting encryption via AWS KMS, environment-specific values, and integration with Systems Manager Parameter Store for secrets.
```python
import os
import boto3
from botocore.exceptions import ClientError
# Access environment variables
DATABASE_URL = os.environ.get("DATABASE_URL")
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
STAGE = os.environ.get("STAGE", "dev")
# Get secret from Parameter Store
def get_secret(secret_name):
ssm = boto3.client("ssm")
try:
response = ssm.get_parameter(
Name=secret_name,
WithDecryption=True
)
return response["Parameter"]["Value"]
except ClientError as e:
print(f"Error fetching secret: {e}")
return None
DB_PASSWORD = get_secret(f"/myapp/{STAGE}/db_password")
What's Next
Now learn about API Gateway Lambda integration in Building Serverless APIs.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro