Installation
Setup Methods
There are two ways to set up Sentry in AWS Lambda:- Automatic (Recommended)
- Manual
Use environment variables for zero-code setup:Configure these in your Lambda function settings or deployment configuration.
Basic Lambda Handler
Async Handler (Recommended)
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:Add Layer to Function
- Go to your Lambda function in AWS Console
- Choose Layers → Add Layer
- Specify ARN:
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
Events Not Captured
Events Not Captured
Ensure:
- NODE_OPTIONS is set correctly
- SENTRY_DSN is configured
- Lambda has internet access (or VPC endpoint)
- Function timeout is adequate for flushing events
High Latency
High Latency
Consider:
- Use asynchronous error reporting
- Reduce tracesSampleRate
- 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