Skip to main content
The Sentry AWS Lambda SDK provides error monitoring and performance tracking for serverless functions running on AWS Lambda with automatic integration and minimal configuration.

Installation

Setup Methods

There are two ways to set up Sentry in AWS Lambda:

Basic Lambda Handler

Callback Handler

Error Handling

Manual Error Capture

Validation Errors

Performance Monitoring

Custom Spans

Database Operations

External API Calls

Context and Tags

Lambda Context

User Identification

Sentry Lambda Layer

Use the official Sentry Lambda Layer for easier deployment:
1

Add Layer to Function

  1. Go to your Lambda function in AWS Console
  2. Choose LayersAdd Layer
  3. Specify ARN:
Get the latest ARN from the docs.
2

Configure Environment Variables

Add these environment variables:

Serverless Framework

Integrate with Serverless Framework:

AWS SAM

Configure with AWS SAM:

Environment Variables

Required

Optional

Event Sources

API Gateway

S3 Events

SQS Events

Best Practices

Use Layers

Use the official Sentry Lambda Layer for easier deployment and updates.

Instrument Early

Initialize Sentry before any other imports using NODE_OPTIONS.

Set Context

Add Lambda context and event data for better debugging.

Sample Wisely

Adjust tracesSampleRate based on traffic to control costs.

Troubleshooting

Ensure:
  1. NODE_OPTIONS is set correctly
  2. SENTRY_DSN is configured
  3. Lambda has internet access (or VPC endpoint)
  4. Function timeout is adequate for flushing events
Consider:
  1. Use asynchronous error reporting
  2. Reduce tracesSampleRate
  3. Enable Lambda SnapStart for faster cold starts

Next Steps

API Gateway

Integrate with API Gateway events

DynamoDB

Track database operations

Step Functions

Monitor workflow executions

Layers

Advanced Lambda Layer configuration