x

[eBook Presented by AWS & Thundra] Mastering Observability on the Cloud 📖 Download:

Online Debugging Java AWS Lambda Functions Using Thundra Debugger

Apr 2, 2020

 

online-debugging-ozge-blog

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 Online 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 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 Thundra Debugger, you can skip it. 

Configuration of Lambda Function for Thundra 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 the Thundra console. Setting up only this variable is sufficient, but you can check out all configuration parameters for Java in this online debugging document. Note that you should consider giving your function a bigger timeout as debugging can take a while. 

image4

Configuration of Intellij IDE for Java for Thundra 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.

image3



Click Install on the plugin page.

image2

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. 

image1

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.

image5

From now on, you can continue debugging like you usually would! To get more information on online debugging with Thundra, check out this document.

Conclusion

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 Debugger. I have shown how to enable debugging for Java, but Thundra 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 document. You can also get more information about debugging Nodejs AWS Lambda functions using Thundra Debugger on this blog post.

Start your native debugging experience by signing up for Thundra for free on our website, or go to the AWS Marketplace. Start following us on Twitter to catch up with our latest announcements.