This is documentation for the next version of Pyroscope. For the latest stable release, go to the latest version.

Open source

AWS Lambda profiling extension

The Pyroscope AWS Lambda extension is a robust tool for profiling AWS Lambda functions, ensuring minimal latency impact. This profiling is essential for optimizing your functions.

Why profile AWS Lambda functions?

AWS Lambda functions, while powerful and flexible, can lead to significant costs if not managed efficiently. Serverless architectures, like AWS Lambda, can mask performance issues. Since Lambda functions are billed based on execution time and allocated memory, code inefficiencies can lead to higher costs. Often, these costs accumulate unnoticed because of the following reasons:

  • Granular billing: Lambda functions are billed in milliseconds, which can make small inefficiencies seem insignificant at first. However, when scaled to thousands or millions of invocations, these inefficiencies can lead to substantial costs.

  • Complex performance profile: Lambda functions may interact with various services and resources, making it challenging to pinpoint performance bottlenecks.

  • Variable load: The serverless nature of AWS Lambda means that functions might handle variable loads at different times, making it hard to optimize for every scenario.

Profiling Lambda functions helps identify these hidden performance bottlenecks, enabling developers to optimize their code for both performance and cost. Effective profiling can reveal inefficient code paths, unnecessary memory usage, and areas where the execution time can be reduced. By addressing these issues, organizations can significantly reduce their AWS bill, improve application responsiveness, and ensure a more efficient use of resources.


This extension runs a relay server on the same network namespace as the Lambda function, ensuring minimal added latency.

Lambda Extension Architecture

For more details, refer to the Building Extensions for AWS Lambda blog post.

Set up the Pyroscope Lambda extension

To set up the Pyroscope Lambda extension, you need to:

  1. Configure your Lambda function
  2. Set up your environment variables
  3. Integrate the Pyroscope SDK

Configure your Lambda function

Configure your Lambda function to use the extension. Find the latest release on our releases page.

Set up the environment variables

Configure the extension with the following environment variables:

Environment VariableDefault ValueDescription
PYROSCOPE_REMOTE_ADDRESShttps://profiles-prod-001.grafana.netDestination for relayed Pyroscope data
PYROSCOPE_BASIC_AUTH_USER""HTTP Basic authentication user
PYROSCOPE_BASIC_AUTH_PASSWORD""HTTP Basic authentication password
PYROSCOPE_SELF_PROFILINGfalseWhether to profile the extension itself
PYROSCOPE_LOG_LEVELinfoLog level (error, info, debug, trace)
PYROSCOPE_TIMEOUT10sHTTP client timeout (in Go duration format)
PYROSCOPE_NUM_WORKERS5Number of relay workers
PYROSCOPE_TENANT_ID""Pyroscope tenant ID (for multi-tenancy)

Integrate the Pyroscope SDK

The Pyroscope AWS Lambda extension is compatible with all existing Pyroscope SDKs. Here are some key considerations:

  • Initialize the SDK before setting up the AWS Lambda handler.
  • Ensure that the Pyroscope server address is configured to http://localhost:4040.

Note that the SDK packages are not automatically included in the extension layer. For Java, Python, Node.js, and Ruby, you must either include the SDK package in the function deployment package or add it as a Lambda layer. Refer to the detailed guide in the AWS Lambda documentation for your specific runtime for further instructions:

For a Golang Lambda function, integrate the Pyroscope SDK as follows:

func HandleRequest(ctx context.Context) (string, error) {
    return "Hello world!", nil

func main() {
        ApplicationName: "simple.golang.lambda",
        ServerAddress:   "http://localhost:4040",

Replace simple.golang.lambda with your application name.

Use cases

Once set up, you can use the Pyroscope UI to analyze your Lambda function’s data to facilitate performance optimizations. For more on this, visit our Pyroscope AWS Lambda Extension blog post.

Send data to Pyroscope

To configure the extension for data transmission:

# PYROSCOPE_TENANT_ID="<TenantID>" # For multi-tenant mode

Replace placeholders accordingly. For sending data to Grafana, use your Grafana stack user and API key for authentication.