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 worksThe 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#
Step 1: Configure your lambda functionIn 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 addressNext, set up a remote address via environment variables where the extension will send data to:
The extension is configured via Environment Variables:
env var | default | description |
---|---|---|
PYROSCOPE_REMOTE_ADDRESS | https://ingest.pyroscope.cloud | the pyroscope instance data will be relayed to |
PYROSCOPE_AUTH_TOKEN | "" | authorization key (token authentication) |
PYROSCOPE_SELF_PROFILING | false | whether to profile the extension itself or not |
PYROSCOPE_LOG_LEVEL | info | error or info or debug or trace |
PYROSCOPE_TIMEOUT | 10s | http client timeout (go duration format) |
PYROSCOPE_NUM_WORKERS | 5 | num of relay workers, pick based on the number of profile types |
#
Step 3: Add the pyroscope agent to your codeFinally, 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 })
lambda.Start(HandleRequest)}
#
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.