One of the biggest pain points of shifting to serverless architectures is debugging. Since developers lost access to the underlying infrastructure, the only resources they now have to debug serverless applications are the logs printed as a result of an invocation. However, it takes a lot of time to write a new logline, deploy the function, and check the logs once again. Step-through debugging, setting breakpoints, and inspecting variables can increase developer efficiency. To some extent, AWS Toolkit and SAM make it easy to perform step-through debugging on your local environment. However, recreating the same AWS environment on your local can be hard because of permissions, triggers, and VPC configurations.
In order to provide the same debugging experience you have on your local environment for Lambdas on the AWS environment, Thundra released AWS Lambda Debugger. It enables you to debug your Lambda in its native environment and use your IDE, giving you the capability to perform traditional debugging tasks such as setting breakpoints, and viewing and changing variables.
Using Thundra's AWS Lambda Debugger with Java AWS Lambda Functions
To give a live demonstration of how to debug using Thundra Debugger, I will use the default project that is created when you build a new serverless application using AWS Toolkit. If you would like to learn how to create a serverless project with AWS Toolkit, check out these documents about setting up and creating an AWS Serverless Application by using the AWS Toolkit for JetBrains. If you already have a project that you would like to set up with Thundra's AWS Lambda Debugger, you can skip it.
Configuration of Lambda Function for Thundra's AWS Lambda Debugger
After setting up a Lambda and deploying it to AWS, you can configure Thundra integration by using one of the integration options. Note that in order to use online debugging features, you need to use Thundra Java agent version 2.5.2 and layer version 42 or higher, and change runtime to Custom runtime. Now you are ready to set up live debugging.
You must set the thundra_agent_lambda_debugger_auth_token environment variable to enable debugging. You can get this token from Thundra APM. Setting up only this variable is sufficient, but you can check out all configuration parameters for Java in this AWS Lambda Debugging documentation. Note that you should consider giving your function a bigger timeout as debugging can take a while.
Configuration of Intellij IDE for Java for Thundra's AWS Lambda Debugger
To set up remote debugging for Java on Intellij IDEA, install the plugin from the marketplace. Open “Preferences” on Intellij IDEA, and search for “Debugger for AWS Lambda” on the marketplace.
Click Install on the plugin page.
After installing the plugin, click on “Run - Edit Configurations,” and click the add button for the new configuration. Choose “Thundra Debugger” for the new configuration. Input your authentication token from the Thundra console, and save the configuration.
Now you’re ready to start debugging! Set a breakpoint on your IDE, click “debug,” and invoke your function. When you invoke the function, your breakpoint will be hit.
From now on, you can continue debugging like you usually would! To get more information on online debugging with Thundra, check out this documentation.
Sometimes, troubleshooting an issue without live debugging can be complicated and time-consuming. But being able to step through debugging live functions in the comfort of traditional debugging on your IDE offers a convenient way to accomplish that task. Now, you can perform it with just a few configuration changes without modifying your code using Thundra's AWS Lambda Debugger. I have shown how to enable debugging for Java, butThundra's AWS Lambda Debugger also supports Nodejs and Python. To make debugging even easier, Thundra has published the VSCode plugin for Nodejs and Python and Intellij plugin for Java. And for other environments, we published a Python client. You can check out how to use it with other environments in this documentation. You can also get more information about debugging Nodejs AWS Lambda functions usingThundra's AWS Lambda Debugger on this blog post and for Python functions on this blog post.