Sentry for AWS Lambda (JavaScript)

AWS Lambda is a serverless compute service offered as part of Amazon Web Services. Learn how to set it up with Sentry.

Looking for instructions on how to add Sentry without modifying your code? Check out these docs instead.

Event Functions or Web Functions?

AWS Lambda offers two function types for Node.js, and each needs a different Sentry setup:

  • Lambda Event Functions run a handler that Lambda invokes in response to events, such as API Gateway requests or SQS messages. Use the @sentry/aws-serverless SDK described on this page.
  • Lambda Web Functions run a standard HTTP server, like Express or Hono, that listens on a port and has no Lambda handler. Use the Node.js SDK instead. Its default awsLambdaWebIntegration adds Lambda metadata, like request IDs and cold starts, to your errors and spans.

On this page you'll get an overview how to install, configure and use Sentry in your AWS Lambda Event Functions (formerly called Lambda functions). Once set up, our SDK will automatically report error and performance data from your functions. Issues in Sentry will automatically include cloudwatch data, function details and execution time measurements.

Depending on your preferences, you can install Sentry in your Event Functions using the Sentry AWS Lambda Layer (recommended) or the Sentry AWS NPM package.

We generally recommend using the Lambda layer as it doesn't require you to deploy any Sentry dependency alongside your function. With the layer, you can achieve the same level of customization as with the NPM package. There are two reasons why you still might want to use the NPM package instead:

  1. You want to minimize function size and tree-shake parts of the SDK code that you don't need. A related reason might be because you're transpiling your code and want to transpile your dependencies as well.
  2. You already use NPM packages and deploy node_modules with your function and you don't want to add a (or another) Lambda layer to your functions.

After installing the SDK, you might want to configure some parameters. Besides the common SDK configuration, you can also configure Sentry's Lambda handler wrapper to optimize function runtime overhead and timeout warnings.

Once set up, verify that Sentry is reporting errors correctly by throwing a sample error in one of your functions:

index.js
exports.handler = async (event, context) => {
throw new Error("This is a test error");
};

  • Explore practical guides on what to monitor, log, track, and investigate after setup
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").