A minimal AWS Lambda function demonstrating:
- Zip code geocoding using external API
- OpenTelemetry distributed tracing with Rotel extension
- Pino logging with OpenTelemetry transport
- AWS CDK infrastructure deployment
Note
Pino uses worker threads to flush log messages asynchronously, which causes difficulties in AWS Lambda environments.
This example performs a flushSync call at the end of execution, but this does not always ensure Pino flushes logs
in time. Logs may get flushed on the next function invocation.
This Lambda function uses:
- Rotel Extension: Lambda extension for OpenTelemetry data forwarding to Axiom
- OpenTelemetry Layer: AWS managed OpenTelemetry instrumentation layer
- Node.js 22.x runtime
- AWS CLI configured with appropriate credentials
- Node.js and npm installed
- AWS CDK CLI (
npm install -g aws-cdk) - Axiom account with API key and dataset
The function is deployed using AWS CDK. Configuration is managed through environment variables.
Bootstrap the CDK environment.
npx cdk boostrapSet these before deploying:
# Required: Axiom configuration
export ROTEL_AXIOM_KEY="your-axiom-api-key"
export ROTEL_AXIOM_DATASET="your-dataset-name"
# Optional: Rotel extension version (default: 36)
export ROTEL_VERSION=36
# Required: AWS credentials
export AWS_PROFILE=your-profile-name
# or use AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY# Install dependencies and deploy with CDK
make deploy
# Or manually:
npm install
npx cdk deploy --require-approval neverThe CDK stack will:
- Create the Lambda function with name
rotel-pino-lambda-example - Attach OpenTelemetry and Rotel extension layers
- Configure environment variables for OTEL integration
- Set up IAM roles and permissions
- Output the function ARN and name
# Test with default zip code (10001)
make invoke
# Test with custom zip code
make invoke-custom
# Local testing (without AWS)
make test-local# Destroy CDK stack
make destroy
# Clean local artifacts
make cleanThe deployed function includes:
- Runtime: Node.js 22.x
- Memory: 512 MB
- Timeout: 10 seconds
- Layers:
- OpenTelemetry Node.js 0.16.0
- Rotel Extension (version configurable via ROTEL_VERSION)
- Logging: JSON format
Request:
{
"zipCode": "10001"
}Response:
{
"zipCode": "10001",
"coordinates": {
"latitude": 40.7505,
"longitude": -73.9934,
"displayName": "10001, New York, NY, United States"
},
"timestamp": "2025-01-15T12:00:00.000Z",
"requestId": "abc123-def456-ghi789"
}