Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit 5089b00

Browse files
authored
feat(node/python): Add example for AWS Lambda & Serverless Framework
Add example for AWS Lambda & Serverless Framework
2 parents 569cd95 + cbc427c commit 5089b00

File tree

8 files changed

+83
-2
lines changed

8 files changed

+83
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Node
2-
node_modulesA
2+
node_modules
33
*.log
44

55
# Mac OS X
@@ -71,3 +71,6 @@ android/app/release/
7171

7272
bin/
7373
obj/
74+
75+
# Serverless Framework
76+
.serverless

aws-lambda/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Sentry for Serverless - AWS Lambda
22

3-
43
Here you find examples of how to use Sentry SDKs to capture errors from code running on AWS Lambda.
54

65
- [Node](node)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Sentry for Serverless Framework - AWS Lambda Layer
2+
3+
```sh
4+
export SENTRY_DSN=https://[email protected]/1234567
5+
npx serverless deploy
6+
npx serverless remove
7+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
service: sentry-node
2+
3+
frameworkVersion: '2'
4+
5+
provider:
6+
name: aws
7+
runtime: nodejs12.x
8+
lambdaHashingVersion: 20201221
9+
environment:
10+
SENTRY_TRACES_SAMPLE_RATE: '1.0'
11+
SENTRY_DSN: ${env:SENTRY_DSN}
12+
NODE_OPTIONS: '-r @sentry/serverless/dist/awslambda-auto'
13+
14+
custom:
15+
layers:
16+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:26
17+
18+
functions:
19+
hello:
20+
handler: unhandled_exception.handler
21+
layers: ${self:custom.layers}
22+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
*******************************************************************************
3+
* File name : unhandled_exception.js
4+
* Description : This file contains code that throws an exception that is unhandled
5+
*
6+
*******************************************************************************
7+
**/
8+
9+
exports.handler = function (event, context, callback) {
10+
throw new Error('Oops something went wrong');
11+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Sentry for Serverless Framework - AWS Lambda Layer
2+
3+
```sh
4+
export SENTRY_DSN=https://[email protected]/1234567
5+
npx serverless deploy
6+
npx serverless remove
7+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
service: sentry-python
2+
3+
frameworkVersion: '2'
4+
5+
provider:
6+
name: aws
7+
runtime: python3.7
8+
lambdaHashingVersion: 20201221
9+
environment:
10+
SENTRY_TRACES_SAMPLE_RATE: '1.0'
11+
SENTRY_DSN: ${env:SENTRY_DSN}
12+
13+
custom:
14+
layers:
15+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryPythonServerlessSDK:6
16+
17+
functions:
18+
hello:
19+
handler: sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler
20+
layers: ${self:custom.layers}
21+
environment:
22+
SENTRY_INITIAL_HANDLER: unhandled_exception.handler
23+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# /**
2+
# *******************************************************************************
3+
# * File name : unhandled_exception.py
4+
# * Description : This file contains code that throws an exception that is unhandled
5+
# *******************************************************************************
6+
# **/
7+
8+
def handler(event, context):
9+
raise Exception('Oops something went wrong')

0 commit comments

Comments
 (0)