Project: Grafana Pyroscope (Observability and Analysis / Observability)
File: aws-lambda.md

title: "AWS Lambda profiling extension" menuTitle: "AWS Lambda profiling extension" description: "Profiling AWS Lambda functions with Pyroscope" weight: 100 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. 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. For more details, refer to the . To set up the Pyroscope Lambda extension, you need to: Configure your Lambda function Set up your environment variables Integrate the Pyroscope SDK Configure your Lambda function to use the extension. Find the latest release on our

Configure the extension with the following environment variables: | Environment Variable | Default Value | Description | | | | -- | | `PYROSCOPEREMOTEADDRESS` | `https://profiles-prod-001.grafana.net` | Destination for relayed Pyroscope data | | `PYROSCOPEBASICAUTH_USER` | `""` | HTTP Basic authentication user | | `PYROSCOPEBASICAUTH_PASSWORD`| `""` | HTTP Basic authentication password | | `PYROSCOPESELFPROFILING` | `false` | Whether to profile the extension itself | | `PYROSCOPELOGLEVEL` | `info` | Log level (`error`, `info`, `debug`, `trace`)| | `PYROSCOPE_TIMEOUT` | `10s` | HTTP client timeout (in Go duration format) | | `PYROSCOPENUMWORKERS` | `5` | Number of relay workers | | `PYROSCOPETENANTID` | `""` | Pyroscope tenant ID (for multi-tenancy) | 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: ```go func HandleRequest(ctx context.Context) (string, error) { return "Hello world!", nil } func main() { pyroscope.Start(pyroscope.Config{ ApplicationName: "simple.golang.lambda", ServerAddress: "http://localhost:4040", }) lambda.Start(HandleRequest) } ``` Replace `simple.golang.lambda` with your application name. 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 . To configure the extension for data transmission: ```bash PYROSCOPEREMOTEADDRESS="<URL>" PYROSCOPEBASICAUTH_USER="<User>" PYROSCOPEBASICAUTH_PASSWORD="<Password>" ``` Replace placeholders accordingly. For sending data to Grafana, use your Grafana stack user and API key for authentication.