Lambda Remote Debugging (Java)
Key
Value
| Services |
Lambda |
| Integrations |
AWS SAM, VS Code, AWS Toolkit for VS Code |
| Categories |
Serverless; Debugging |
A Hello World Java Lambda function demonstrating interactive breakpoint debugging using LocalStack Lambda Remote Debugging. LocalStack automatically configures debugging and adjusts relevant timeouts. The recommended setup uses the AWS Toolkit for VS Code for one-click debugging.
make check
make install
- Execute the VS Code command "LocalStack: Run Setup Wizard" using the LocalStack Toolkit
- Start LocalStack by clicking on the LocalStack Toolkit status bar
Deploy the Lambda function
- Run make build
- Run make deploy
Debugging the Lambda function
- Open the Remote invoke configuration in the AWS Toolkit
- Open the AWS Toolkit extension
- Expand the AWS Explorer and Lambda node
- Navigate to the function you want to debug, then choose the Invoke remotely icon ▶️ from the context menu
- Select the Remote debugging check box to display the remote debugging properties
- Specify the Local Root Path to your local handler file.
- Set a breakpoint in your handler file by clicking in the gutter-margin
- Click the Remote invoke button to invoke the Lambda function
-
Start LocalStack with the following configuration:
LOCALSTACK_AUTH_TOKEN=<your-auth-token> \
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.yaml
- LOCALSTACK_AUTH_TOKEN=<your-auth-token> is the authentication token for LocalStack
- LOCALSTACK_LAMBDA_DEBUG_MODE=1 adjusts timeouts
- LOCALSTACK_LAMBDA_DEBUG_MODE_CONFIG_PATH=/tmp/lambda_debug_mode_config.yaml points to the config file for Lambda debug mode allowing for advanced configuration. It maps the Lambda function arn:aws:lambda:us-east-1:000000000000:function:HelloWorldFunctionJava to port 5050.
- --volume $PWD/lambda_debug_mode_config.yaml:/tmp/lambda_debug_mode_config.yaml maps the Lambda debug configuration from the host into the LocalStack Docker container for hot-reloading configuration updates.
Deploy the Lambda function
- Run make build to build the Lambda ZIP package
- Run make deploy to deploy the Lambda function
Debug the Lambda function
- Open the sample folder in VS Code to auto-detect .vscode/launch.json
- Set a breakpoint in the handler file HelloWorldFunction/src/main/java/helloworld/App.java by clicking in the gutter-margin
- Open the Run and Debug view in VS Code
- Run the Java: Remote Attach task
- Run make invoke to invoke the Lambda function
- Concurrent invokes are currently rejected with a ResourceConflictException.
Upvote this GitHub issue if this affects you.
The code in this sample is available under the Apache 2.0 license.