Skip to content

streamfold/rotel-pino-lambda-example

Repository files navigation

Rotel Pino Lambda Example

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.

Architecture

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

Prerequisites

  • 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

Deployment

The function is deployed using AWS CDK. Configuration is managed through environment variables.

Bootstrap

Bootstrap the CDK environment.

npx cdk boostrap

Environment Variables

Set 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

Deploy

# Install dependencies and deploy with CDK
make deploy

# Or manually:
npm install
npx cdk deploy --require-approval never

The CDK stack will:

  1. Create the Lambda function with name rotel-pino-lambda-example
  2. Attach OpenTelemetry and Rotel extension layers
  3. Configure environment variables for OTEL integration
  4. Set up IAM roles and permissions
  5. Output the function ARN and name

Testing

# Test with default zip code (10001)
make invoke

# Test with custom zip code
make invoke-custom

# Local testing (without AWS)
make test-local

Cleanup

# Destroy CDK stack
make destroy

# Clean local artifacts
make clean

Lambda Configuration

The 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

Example Request/Response

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"
}

About

Rotel example with Pino.js and AWS Lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published