A simple demo application showcasing how to debug Java Lambdas locally with Lambda Debug Mode. The demo deploys a Lambda function with a one-second timeout, which is automatically lifted when running LocalStack with Lambda Debug Mode enabled.
- LocalStack
- Docker
makeawslocaljava17andgradle(optional for local build)
To build the Lambda function archive:
make installMake sure that LocalStack is started with the following configuration:
LOCALSTACK_LAMBDA_DEBUG_MODE=1 \
LOCALSTACK_LAMBDA_DEBUG_MODE_CONFIG_PATH=/tmp/lambda_debug_mode_config.yaml \
localstack start --volume $PWD/lambda_debug_mode_config.yaml:/tmp/lambda_debug_mode_config.yamlLOCALSTACK_LAMBDA_DEBUG_MODE=1enables the Lambda debug modeLOCALSTACK_LAMBDA_DEBUG_MODE_CONFIG_PATH=/tmp/lambda_debug_mode_config.yamlpoints to the config file for Lambda debug mode allowing for advanced configuration. It maps the Lambda functionarn:aws:lambda:us-east-1:000000000000:function:function-oneto port5050.--volume $PWD/lambda_debug_mode_config.yaml:/tmp/lambda_debug_mode_config.yamlmaps the Lambda debug configuration from the host into the LocalStack Docker container for hot-reloading.
The project requires you to configure your IDE or editor of choice to debug remote Java Lambda functions on port 5050. These documentations include a guide on how you can do so.
The following command used to deploy and invoke the Lambda locally:
make runAfter the Lambda function is invoked you can switch to your IDE or editor of choice, set a breakpoint in the Lambda handler, and run the remote debugger. LocalStack will automatically waive the set one second timeout for the Lambda function, giving you ample time to connect the debugger and debug the logic in the function.
The code in this sample is available under the Apache 2.0 license.