Lambda Layer
Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions
The easiest way to get started with Sentry is to use the Sentry Lambda Layer instead of installing @sentry/aws-serverless
with a package manager manually. If you follow this guide, you don't have to worry about deploying Sentry dependencies alongside your function code.
Before you begin, make sure you have the following:
- You have a Lambda function deployed in AWS.
- You know the AWS region that your function is deployed to.
Add the Sentry Layer by navigating to your Lambda function. Select Layers, then Add a Layer.
Specify an ARN tab as illustrated:
Finally, set the region and copy the provided ARN value into the input.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Set the following environment variables in your Lambda function configuration:
NODE_OPTIONS="--import @sentry/aws-serverless/awslambda-auto"
SENTRY_DSN="https://examplePublicKey@o0.ingest.sentry.io/0"
# performance
SENTRY_TRACES_SAMPLE_RATE="1.0"
# performance
To set environment variables, navigate to your Lambda function, select Configuration, then Environment variables:
To further customize the SDK setup, you can also manually initialize the SDK in your lambda function. The benefit of this installation method is that you can fully customize your Sentry SDK setup in a Sentry.init
call.
Note that you don't have to actually install an NPM package for this to work, as the package is already included in the Lambda Layer.
Create a new file, for example instrument.js
to initialize the SDK:
instrument.js
const Sentry = require("@sentry/aws-serverless");
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/aws-lambda/configuration/options/#sendDefaultPii
sendDefaultPii: true,
// performance
// Add Tracing by setting tracesSampleRate and adding integration
// Set tracesSampleRate to 1.0 to capture 100% of transactions
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// performance
});
To load the SDK before your function starts, you need to preload the instrument.js
by setting the NODE_OPTIONS
environment variable:
NODE_OPTIONS="--import ./instrument.js"
That's it — make sure to re-deploy your function and you're all set!
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").