Apply the CodeGuru Profiler function decorator to your handler function
Pull your codeguru_profiler_agent
dependency to your local environment
through pip
and include it in the .zip file for Lambda.
The only required configuration option to start the agent is the profiling group name. You can find this in the Settings section of your profiling group on the CodeGuru Profiler console. You can also provide the Region if you want to use a profiling group that was created in a different region than the one where Lambda is running. You can also provide the profiling group ARN directly, which contains both the name and Region. Either the profiling group name or ARN must be provided.
Option | Environment variable key | Environment variable value | Decorator argument example |
---|---|---|---|
Profiling group name |
|
|
|
Profiling group ARN |
|
|
An ARN cannot be passed as a decorator argument |
Region |
|
|
|
Decorate your handler function with @with_lambda_profiler()
. The following
example shows what your handler function code looks like with CodeGuru Profiler turned on.
from codeguru_profiler_agent import with_lambda_profiler @with_lambda_profiler(profiling_group_name="MyGroupName") def handler_name(event, context): return "Hello World"
Only decorate your handler function. You do not have to decorate other internal functions. You can pass the profiling group name directly in the decorator, or with environment variables.