Skip to main content

AWS Lambda

What is Pyroscope Lambda Extension?#

The Pyroscope AWS Lambda Extension (github) allows profiling lambda functions with very little latency overhead over your existing code.

How it works#

The Pyroscope Lambda Extension runs a relay server on port 4040 in the same network namespace as the lambda function. This allows the Pyroscope Agent to run as normal and send data to the relay server while adding minimal latency in the lambda handling. lambda_image_04-01

For more information on how AWS Lambda Extensions work, check the Building Extensions for AWS Lambda blogpost.

Basic example#

Step 1: Configure your lambda function#

In order to use the extension you'll first need to configure your Lambda function to use the extension. You can find the most recent release on our releases page.

Step 2: Set up remote address#

Next, set up a remote address via environment variables where the extension will send data to:

The extension is configured via Environment Variables:

env vardefaultdescription
PYROSCOPE_REMOTE_ADDRESShttps://ingest.pyroscope.cloudthe pyroscope instance data will be relayed to
PYROSCOPE_AUTH_TOKEN""authorization key (token authentication)
PYROSCOPE_SELF_PROFILINGfalsewhether to profile the extension itself or not
PYROSCOPE_LOG_LEVELinfoerror or info or debug or trace
PYROSCOPE_TIMEOUT10shttp client timeout (go duration format)
PYROSCOPE_NUM_WORKERS5num of relay workers, pick based on the number of profile types

Step 3: Add the pyroscope agent to your code#

Finally, add the Pyroscope Agent to the function. While this example shows configuration for a golang application, you can use the same configuration for any language.

func HandleRequest(ctx context.Context) (string, error) {    return fmt.Sprintf("Hello world!"), nil}
func main() {    // start the pyroscope agent before handling requests    pyroscope.Start(pyroscope.Config{        ApplicationName: "simple.golang.lambda", // YOUR APP NAME        ServerAddress:   "http://localhost:4040", // MUST BE localhost:4040    })

What are the use cases?#

Once you've completed the above steps, you'll be able to use the Pyroscope UI to analyze data surrounding your lambda function and make optimizations accordingly. To learn more about the use case for the extension, check out the Pyroscope AWS Lambda Extension blogpost.