This guide provides comprehensive information about configuring the Lambda Starter application and its infrastructure.
The application configuration is managed through environment variables. These variables are validated using Zod schemas at runtime to ensure proper configuration.
The following environment variables are available for configuring the application:
| Variable | Type | Description | Default | Required |
|---|---|---|---|---|
TASKS_TABLE |
string | The name of the DynamoDB table for storing tasks | - | Yes |
TASK_EVENT_TOPIC_ARN |
string | The ARN of the SNS topic for task events | - | Yes |
AWS_REGION |
string | The AWS region where resources are deployed | us-east-1 |
No |
USE_LOCALSTACK |
boolean | Enable LocalStack mode for local development | false |
No |
LOCALSTACK_ENDPOINT |
string | LocalStack endpoint URL | http://localstack:4566 |
No |
LOGGING_ENABLED |
boolean | Enable or disable application logging | true |
No |
LOGGING_LEVEL |
enum | Logging level: debug, info, warn, error |
debug |
No |
LOGGING_FORMAT |
enum | Logging format: text, json |
json |
No |
CORS_ALLOW_ORIGIN |
string | CORS allow origin header value | * |
No |
Application configuration is accessed through the config object exported from src/utils/config.ts:
import { config } from './utils/config';
console.log(`Tasks table: ${config.TASKS_TABLE}`);
console.log(`Task event topic ARN: ${config.TASK_EVENT_TOPIC_ARN}`);
console.log(`Logging enabled: ${config.LOGGING_ENABLED}`);The application uses Zod to validate environment variables at startup. If validation fails, the application will throw an error with details about the validation issues.
The infrastructure configuration is managed through environment variables prefixed with CDK_. These variables control how AWS resources are provisioned using the AWS CDK.
The following environment variables are available for configuring the infrastructure:
| Variable | Type | Description | Default | Required |
|---|---|---|---|---|
CDK_APP_NAME |
string | The application name used in resource naming | lambda-starter |
No |
CDK_ENV |
enum | Environment: local, dev, qat, prd |
- | Yes |
CDK_ACCOUNT |
string | AWS account ID for deployment | - | No |
CDK_REGION |
string | AWS region for deployment | - | No |
CDK_USE_LOCALSTACK |
boolean | Enable LocalStack mode for local development | false |
No |
CDK_LOCALSTACK_ENDPOINT |
string | LocalStack endpoint URL | http://localstack:4566 |
No |
CDK_OU |
string | Organizational Unit for resource tagging | leanstacks |
No |
CDK_OWNER |
string | Owner tag for resource tracking | unknown |
No |
CDK_CORS_ALLOW_ORIGIN |
string | CORS allow origin for API Gateway and Lambda functions | * |
No |
CDK_APP_LOGGING_ENABLED |
boolean | Enable logging in Lambda functions | true |
No |
CDK_APP_LOGGING_LEVEL |
enum | Logging level: debug, info, warn, error |
info |
No |
CDK_APP_LOGGING_FORMAT |
enum | Logging format: text, json |
json |
No |
Infrastructure configuration is managed through the getConfig() function in infrastructure/utils/config.ts:
import { getConfig } from './utils/config';
const config = getConfig();
console.log(`Environment: ${config.CDK_ENV}`);
console.log(`App name: ${config.CDK_APP_NAME}`);Infrastructure configuration can be provided through:
- Environment variables - Set directly in your shell or CI/CD pipeline
- .env file - Create a
.envfile in theinfrastructure/directory for local development
Example .env file for AWS deployment:
##################################################
#### Infrastructure Environment Configuration ####
##################################################
### Application Configuration ###
## Application name (default: lambda-starter)
CDK_APP_NAME=lambda-starter
## The infrastructure environment (dev, qat, prd)
CDK_ENV=dev
### Resource Tagging Configuration ###
## Organizational Unit (e.g., software-engineering, shared-services)
CDK_OU=software-engineering
## Owner of the infrastructure resources (e.g., team-alpha, Joe Engineer)
CDK_OWNER=microservices-team
### Logging Configuration ###
## Application logging level: debug, info, warn, error (default: info)
CDK_APP_LOGGING_LEVEL=debugExample .env file for LocalStack local development:
##################################################
#### LocalStack Environment Configuration #######
##################################################
### Application Configuration ###
## Application name (default: lambda-starter)
CDK_APP_NAME=lambda-starter
## The infrastructure environment (local for LocalStack)
CDK_ENV=local
### LocalStack Configuration ###
## Enable LocalStack mode
CDK_USE_LOCALSTACK=true
## LocalStack endpoint (default: http://localstack:4566)
CDK_LOCALSTACK_ENDPOINT=http://localstack:4566
### AWS Configuration ###
## AWS Region for LocalStack (default: us-east-1)
CDK_REGION=us-east-1
### Resource Tagging Configuration ###
## Organizational Unit
CDK_OU=software-engineering
## Owner of the infrastructure resources
CDK_OWNER=local-dev
### Logging Configuration ###
## Enable application logging
CDK_APP_LOGGING_ENABLED=true
## Application logging level: debug, info, warn, error
CDK_APP_LOGGING_LEVEL=debug
## Application logging format: text, json (text is easier to read locally)
CDK_APP_LOGGING_FORMAT=text
### CORS Configuration ###
## CORS allow origin for API Gateway (allowing all for local development)
CDK_CORS_ALLOW_ORIGIN=*Important: Never commit .env files containing sensitive information to source control.
All AWS resources created by the CDK are automatically tagged with the following tags:
| Tag | Description | Source |
|---|---|---|
App |
Application name | CDK_APP_NAME |
Env |
Environment (local, dev, qat, prd) | CDK_ENV |
OU |
Organizational Unit | CDK_OU |
Owner |
Team or individual responsible | CDK_OWNER |
These tags are used for cost allocation, resource management, and identifying resources in AWS.
Different environments may require different configuration values. Consider these recommendations:
CDK_ENV=local- Enables LocalStack modeCDK_USE_LOCALSTACK=true- Required for LocalStackCDK_LOCALSTACK_ENDPOINT=http://localstack:4566- LocalStack endpoint (uses Docker container hostname)CDK_APP_LOGGING_LEVEL=debug- Verbose logging for developmentCDK_APP_LOGGING_FORMAT=text- Human-readable logs for local debuggingCDK_CORS_ALLOW_ORIGIN=*- Allow all origins for local testing- No AWS account required - LocalStack uses mock credentials
- See the LocalStack Guide for complete setup instructions
CDK_APP_LOGGING_LEVEL=debug- Verbose logging for developmentCDK_CORS_ALLOW_ORIGIN=*- Allow all origins for easier testing- Use minimal resource sizes to reduce costs
CDK_APP_LOGGING_LEVEL=info- Balanced loggingCDK_CORS_ALLOW_ORIGIN=https://qat.example.com- Restrict to QA environment- Use production-like resource sizes
CDK_APP_LOGGING_LEVEL=warnorerror- Minimal logging for performanceCDK_CORS_ALLOW_ORIGIN=https://example.com- Restrict to production domain- Use appropriate resource sizes and retention policies
- Enable additional monitoring and alerting
The configuration flow from infrastructure to application is as follows:
-
Infrastructure Deployment
- CDK reads
CDK_*environment variables - CDK provisions AWS resources with configured values
- Lambda functions receive environment variables from CDK configuration
- CDK reads
-
Application Runtime
- Lambda functions read their environment variables
- Application config validates variables using Zod schemas
- Application uses validated configuration for runtime behavior
Infrastructure configuration variables are passed to Lambda functions with modified names:
| Infrastructure Variable | Lambda Environment Variable |
|---|---|
CDK_USE_LOCALSTACK |
USE_LOCALSTACK |
CDK_LOCALSTACK_ENDPOINT |
LOCALSTACK_ENDPOINT |
CDK_APP_LOGGING_ENABLED |
LOGGING_ENABLED |
CDK_APP_LOGGING_LEVEL |
LOGGING_LEVEL |
CDK_APP_LOGGING_FORMAT |
LOGGING_FORMAT |
CDK_CORS_ALLOW_ORIGIN |
CORS_ALLOW_ORIGIN |
| (DynamoDB table name) | TASKS_TABLE |
| (SNS topic ARN) | TASK_EVENT_TOPIC_ARN |
| (AWS Region) | AWS_REGION |
If you encounter configuration validation errors:
- Check required variables - Ensure all required variables are set
- Verify enum values - Check that enum values match allowed options
- Review error messages - Validation errors include the field name and specific issue
Example error:
Configuration validation failed:
LOGGING_LEVEL: Invalid enum value. Expected 'debug' | 'info' | 'warn' | 'error', received 'verbose'
Environment variables can be set in multiple places. The precedence order is:
- System environment variables (highest priority)
.envfile (infrastructure only)- Default values in schema (lowest priority)
- Never commit secrets - Use AWS Secrets Manager or Parameter Store for sensitive data
- Use .env for local development - Keep local configuration separate from code
- Document custom variables - Update this guide when adding new configuration options
- Validate early - Use Zod schemas to catch configuration errors at startup
- Use environment-specific values - Configure resources appropriately for each environment
- Tag all resources - Ensure proper tagging for cost allocation and management
For more information about this project, see the main README or visit the documentation.