AWS Lambda

Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see Building an AWS Lambda deployment package for Node.js.

Install our Node.js SDK using npm:

Copied
$ npm install @sentry/node

To set up Sentry error logging for a Lambda Function, build a wrapper:

Copied
"use strict";

const Sentry = require("@sentry/node");

Sentry.init({
  dsn: "PUBLIC_DSN"
});

function sentryHandler(lambdaHandler) {
  return async event => {
    try {
      return await lambdaHandler(event);
    } catch (e) {
      Sentry.captureException(e);
      await Sentry.flush(2000);
      return e;
    }
  };
}

module.exports.hello = sentryHandler(async event => {
  notExistFunction();
  return event;
});

You can obtain the DSN using your Sentry account from your organization's Settings > Projects > Client Keys (DSN) in the Sentry web UI.

Note: You need to call both captureException and flush for captured events to be successfully delivered to Sentry.

Create the deployment package in .zip format, then upload it to AWS Lambda as a Lambda Function. Checkout Sentry's aws sample apps for detailed examples. Refer to the JavaScript docs for more configuration options.

You can edit this page on GitHub.