Rob Ribeiro in aws 1 minute to read

Introducing Live Debugging in AWS Lambda

AWS Lambda makes it easy for developers to write and deploy code at almost limitless scale. What has been hard is debugging that code. Live debugging has been a pipe dream, and offline tools work most of the time but not for everything. We managed to change that with a new release: AWS Lambda Debugger.

In a few steps, you can now remote debug any Lambda function running on Node 6.10. Best of all, it’s free under MIT.

How?

Short answer: Magic and Mirrors :)

Long answer: We fork your code to a separate child process that is running in debug mode and connected to the original via an interprocess communication channel. The parent process opens 2 WebSockets as well: one to the child process’ V8 Inspector and the other to a broker server, becoming a proxy between the 2 connections. Next, the developer connects a debugger to the broker server, which connects them to the proxy, which is connected to the child’s debugger port. Now, you have a 3 hop chain like this:

Debugger <=> Broker <=> Proxy <=> Child

Once the developer’s debugger connects to the broker server, the debug version of the handler is executed. The proxy and the child coordinate via the interprocess communication channel to shim the event, context, and callback. Result: the developer is connected to a live running Lambda function with full control.

What’s next?

Our next steps: We’ll be working on this further and writing some more posts about what we learned by doing this.

Your next steps: Deploy a broker in your account and take it for a spin. All of the instructions are in the repo here.

This project is still very new, so if something breaks, file an issue or send a PR. If your needs run deeper than this and you want to talk to some people who now know Lambda inside and out, feel free to reach out to us at info@trek10.com for more.

Thanks for reading!