---
title: "Debug errors in Lambda functions"
url: "https://blog.sentry.io/debug-errors-in-lambda-functions/"
canonical_url: "https://blog.sentry.io/debug-errors-in-lambda-functions/"
authors: ["AJ Jindal"]
published: "2020-10-01"
category: "Product Updates"
---

# Debug errors in Lambda functions

Troubleshooting production issues in Lambda environments is often challenging. CloudWatch requires developers to comb through logs, search for relevant terms that they may not always know of and has hard-to-consume stack traces.

For obvious reasons, we recommend using [Sentry](https://sentry.io/) to instrument your Lambda Functions code in order to report error stack traces and associated debugging context.

Here’s a walk through on how to instrument a Node function. If you are using Python environment, there are parallel [docs](https://docs.sentry.io/platforms/python/integrations/aws-lambda/).

Step 1: Create a dummy function to test the error reporting - we created a simple function that calls an unknown function.

```plaintext
const mySyncHandler = (event, context, callback) => {

  notDefinedFunc();
};
```

Step 2: Add Sentry to the Node folder - we used npm for this example, but you can use yarn too.

```plaintext
npm install --save @sentry/serverless
```

Step 3: Initialize Sentry in the Lambda function - Import Sentry’s Serverless package and wrap your handler.

```plaintext
const Sentry = require("@sentry/serverless");

Sentry.init({
  dsn:
    "Get your dsn by creating a free account with Sentry",
});

const mySyncHandler = (event, context, callback) => {

  notDefinedFunc();
};

exports.handler = Sentry.AWSLambda.wrapHandler(mySyncHandler);
```

That’s it. You now have visibility into errors from my Lambda functions.

The stack traces are detailed and point you to the line of code that’s causing the exception.

![Stack trace screenshot with Sentry for Lambda function](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-0.lJm8d_3r.png&w=1920&q=100)

Function context like `aws_request_id` and `remaining_time_in_milis` are super helpful. In addition, you get deep links to CloudWatch logs.

![Additional info on lambda error](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-1.BRByNyIJ.png&w=1080&q=100)

For extra credit, I made couple customizations to my error reporting:

1.  I really care about timeout issues. They end up bleeding into unknown issues that are difficult to debug. So, I enabled timeout warnings.

```plaintext
exports.handler = Sentry.AWSLambda.wrapHandler(yourHandler, {
  captureTimeoutWarning: false,
});
```

1.  Also, while Sentry automatically captured breadcrumbs from console logs, I added some of my own.

```plaintext
Sentry.addBreadcrumb({
  category: "auth",
  message: "Authenticated user " + user.email,
  level: Sentry.Severity.Info,
});
```

With this instrumentation, I can quickly identify issues, reproduce issues in my local environment and get to the root cause of the problem.

Looking for a bit more help? Our [Lambda Docs](https://docs.sentry.io/platforms/python/integrations/aws-lambda/) are a great place to start. And if you have questions or feedback, visit our [Python SDK on GitHub](https://github.com/getsentry/sentry-python), or shout out to our [support engineers](https://help.sentry.io/). They’re here to help. And also to code. But mostly to help.
