Deep Dive: AWS Lambda Functions

Deep Dive: Go Agent Configuration for AWS Lambda Functions

This page is a deep dive into configuring the SeaLights Go Agent for AWS Lambda Functions. For more direct instructions, visit Using the SeaLights Go Agent with a Lambda Function.

Go Agent Configuration for AWS Lambda Functions

AWS Lambda functions have unique performance and network constraints that require specialized agent configuration. The SeaLights Go Agent provides Light Mode specifically designed for Lambda environments.

Why Light Mode is Required for Lambda

Lambda functions must start quickly and minimize resource usage. The standard SeaLights agent includes background processes that are incompatible with Lambda's execution model:

  • Cold Start Impact: Background processes increase Lambda initialization time

  • Memory Constraints: Multiple agent threads consume precious Lambda memory allocation

  • Network Efficiency: Lambda benefits from optimized network routing via collectors

  • Execution Model: Lambda's stateless nature doesn't require persistent agent connections

What Light Mode Does

Light Mode transforms the agent into a lightweight coverage collector by:

Processes Disabled:

  • Agent heartbeat communication

  • Remote configuration retrieval

  • Log submission to SeaLights backend

  • Idle mode notifications

  • Test event processing (footprints only)

Optimizations Enabled:

  • Preferential use of collector URLs for network efficiency

  • Special agent mode headers for backend optimization

  • Simplified footprint reporting without execution ID requirements

  • Reduced memory footprint and CPU usage

Required Configuration

Environment Variables (Set in Lambda Configuration):

SL_LIGHT_MODE=true
SL_COLLECTOR_URL=<your-collector-endpoint>

Why Runtime Configuration: These parameters should be set as Lambda environment variables, not during the build-time config/instrument steps. Setting SL_LIGHT_MODE=true during build configuration can interfere with unit test coverage collection during development.

Technical Implementation Details

When Light Mode is enabled, the agent:

  1. Simplified Startup: Skips standard agent initialization processes

  2. Footprint Only: Processes lightweight coverage footprints

  3. Collector Priority: Routes all traffic through collector URLs (as configured with SL_COLLECTOR_URL

Performance Benefits

Cold Start Optimization:

  • Eliminates background goroutines that delay Lambda initialization

  • Reduces memory allocation during startup

  • Minimizes network connections during function bootstrap

Runtime Efficiency:

  • Lower CPU usage through simplified processing

  • Reduced memory footprint

  • Optimized network routing through collector infrastructure

  • No persistent connections or heartbeat overhead

Deployment Examples

Lambda Environment Variables:

SL_LIGHT_MODE=true
SL_COLLECTOR_URL=https://your-collector.example.com
SL_TOKEN=your-sealights-token
SL_LAB_ID=lambda-production-environment

Terraform Configuration:

resource "aws_lambda_function" "instrumented_function" {
  # ... other configuration
  
  environment {
    variables = {
      SL_LIGHT_MODE     = "true"
      SL_COLLECTOR_URL  = var.sealights_collector_url
      SL_TOKEN          = var.sealights_token
      SL_LAB_ID         = "lambda-${var.environment}"
    }
  }
}

Important Limitations

Use Only for Lambda: Light Mode should exclusively be used for Lambda functions. It disables agent features that are beneficial for long-running applications and test runners.

Coverage Collection: Light Mode is designed for Coverage Listener Mode only. It cannot be used effectively in Test Runner Mode.

Feature Restrictions: Remote configuration, agent statistics, and real-time monitoring features are unavailable in Light Mode.

Collector Configuration

For collector setup and configuration details, refer to the SeaLights Collector Documentation.

The collector provides:

  • Reduced network latency for Lambda functions

  • Optimized data routing to SeaLights backend

  • Regional deployment options for compliance requirements

Last updated

Was this helpful?