lambda-handler-pattern
Installation
SKILL.md
Lambda Handler Pattern
This is a reference pattern. Learn from the approach, adapt to your context — don't copy verbatim.
Problem: Lambda functions need environment variables and AWS clients, but improper initialization causes cold start issues or hard-to-test code.
Solution: Initialize and validate everything at module level (runs once on cold start), inject dependencies into pure helper functions.
Core Pattern
Key Principle: Lambda environment variables are immutable at runtime. Validate once on cold start, use safely throughout the module.
Module Level: Environment Variables + AWS Clients
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';