Skip to content

Commit 522fb4c

Browse files
connoradsahmedetefy
authored andcommitted
feat(aws-lambda): Add Serverless Framework code snippet for Python (#3830)
* Add Serverless Framework example for Python * Refactored aws lambda code snippets for better readability * Add missing functions conf + rename layersResource back to custom Co-authored-by: Ahmed Etefy <[email protected]>
1 parent f44d1cf commit 522fb4c

File tree

1 file changed

+43
-6
lines changed
  • src/docs/product/integrations/cloud-monitoring/aws-lambda

1 file changed

+43
-6
lines changed

src/docs/product/integrations/cloud-monitoring/aws-lambda/index.mdx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,59 @@ Learn more about [how this integration works](/product/integrations/cloud-monito
9696

9797
## Serverless Framework
9898

99-
Note that this integration will configure your existing lambda functions correctly to use the SDK layer and set the appropriate environment variables as per [how this integration works](/product/integrations/cloud-monitoring/aws-lambda/how-it-works/). You can check the output `aws lambda get-function-configuration --function-name <yourFunctioName>` and this works.
99+
Note that this integration will configure your existing lambda functions correctly to use the SDK layer and set the appropriate environment variables as per [how this integration works](/product/integrations/cloud-monitoring/aws-lambda/how-it-works/). You can check the output `aws lambda get-function-configuration --function-name <yourFunctionName>` and this works.
100100
However when you perform a subsequent `sls deploy` the environment variables are not maintained but it appears the reference to the layer is retained. A workaround exists where you can set the layer definition and environment variables in `serverless.yml`. There are two problems with this, you have to manually add the reference to the SDK layer for every function you want "Sentrified" and you can't maintain the latest layer version automatically.
101+
102+
### Node
101103
```
104+
# other configuration
105+
106+
provider:
107+
108+
# more configuration
109+
region: <AWS_REGION>
110+
102111
environment:
103112
SENTRY_TRACES_SAMPLE_RATE: '1.0'
104-
SENTRY_DSN: '<your sentry dsn>'
113+
SENTRY_DSN: '<SENTRY_DSN>'
105114
NODE_OPTIONS: '-r @sentry/serverless/dist/awslambda-auto'
106115
107116
custom:
108117
layers:
109-
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:8
118+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:26
110119
# - arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:latest
111120
112-
myHandler:
113-
handler: src/handlers/myHandler.handler
114-
layers: ${self:custom.layers}
121+
functions:
122+
<yourFunctionName>:
123+
handler: <yourLambdaHandlerFunctionPath>
124+
layers: ${self:custom.layers}
125+
```
126+
127+
### Python
128+
```
129+
# other configuration
130+
131+
provider:
132+
133+
# more configuration
134+
region: <AWS_REGION>
135+
136+
environment:
137+
SENTRY_TRACES_SAMPLE_RATE: '1.0'
138+
SENTRY_DSN: '<SENTRY_DSN>'
139+
140+
custom:
141+
layers:
142+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryPythonServerlessSDK:6
143+
# - arn:aws:lambda:${self:provider.region:943013980633:layer:SentryPythonServerlessSDK:latest
144+
145+
functions:
146+
<yourFunctionName>:
147+
  handler: sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler
148+
  environment:
149+
  SENTRY_INITIAL_HANDLER: '<yourLambdaHandlerFunctionPath>'
150+
  layers: ${self:custom.layers}
115151
```
152+
116153
Currently there is no way of using the [latest layer plugin](https://www.npmjs.com/package/serverless-latest-layer-version) since the lambda:ListLayerVersions on resource: arn:aws:lambda:eu-west-1:943013980633:layer:SentryNodeServerlessSDK has not been given the necessary permissions.
117154
It is a relatively new integration but there is defintely a case to write a serverless plugin to make this super-smooth. There is an [older version](https://www.serverless.com/plugins/serverless-sentry-plugin) but it requires code changes to the handler and doesn't use `NODE_OPTIONS`. A new plugin could also add the Sentry layer to every function automatically.

0 commit comments

Comments
 (0)