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.

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

Basic example#

First, configure your Lambda function to use the extension.

Next, set up a remote address the extension will send data to, using the environment variable PYROSCOPE_REMOTE_ADDRESS. For more info see the Configuration section.

Finally, add the Pyroscope Agent to the function:

go#

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    })
    lambda.Start(HandleRequest)}

What are the use cases?#

The Pyroscope Lambda Extension works with any AWS Lambda function in any language.

The extension is most useful in cases where lambdas are "busy" enough and run long enough to capture meaningful data. Due to Pyroscope being a sampling profile, when lambda functions are short-lived it may be possible for the lambda to run so fast that no data is sampled in that short time span.

Configuration#

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

Caveats#

You will still be billed by the entire execution (how long the lambda extension runs). The only optimization the Extension does is regarding lambda latency and execution time.