Lambda Debugging
While it is not (yet) possible to attach a debugger to a running Lambda function, the ALambda
Debug Logging
Lambda functions deployed by LambdaSharp have a DEBUG_LOGGING_ENABLED
environment variable to enable debug logging after deployment. By default, DEBUG_LOGGING_ENABLED
is set to false
.
At runtime, the value of the DEBUG_LOGGING_ENABLED
environment variable can be checked through the Debug
Debug statements are logged by using Log*** DEBUG:
prefix:
*** DEBUG: this entry is only emitted when debug logging is enabled
For complex debug statements, it is best practice to first check the Debug
if(DebugLoggingEnabled) {
LogDebug(CreateComplexDebugStatement());
}
Enable Debug Logging in the AWS Console
To enable debug logging temporarily, follow these steps:
- Go to the AWS Console
- Locate the Lambda function
- Click Edit next to the environment variables section
- Change the value for
DEBUG_LOGGING_ENABLED
totrue
- Click Save.
This operation will restart the Lambda function with debug logging enabled. Note when the Lambda function is redeployed, the environment variables will be reset.
Enable Debug Logging in the Module
To enable debug logging permanently, edit the Lambda function declaration as follows:
- Function: MyFunction
Memory: 256
Timeout: 30
Properties:
Environment:
Variables:
DEBUG_LOGGING_ENABLED: true
Request/Response Logging
The most common use case for debug logging is to inspect the request or response of the Lambda function. This use case is covered out of the box by the ALambda
When debug logging is enabled, the ALambda
Request Stream:
*** DEBUG: request stream: { ... }
Response Stream:
*** DEBUG: response stream: { ... }