Skip to content

Commit e372e2e

Browse files
committed
Refactored aws lambda code snippets for better readability
1 parent 4780337 commit e372e2e

File tree

1 file changed

+26
-16
lines changed
  • src/docs/product/integrations/aws-lambda

1 file changed

+26
-16
lines changed

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,43 +94,53 @@ Learn more about [how this integration works](/product/integrations/aws-lambda/h
9494

9595
## Serverless Framework
9696

97-
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/aws-lambda/how-it-works/). You can check the output `aws lambda get-function-configuration --function-name <yourFunctioName>` and this works.
97+
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/aws-lambda/how-it-works/). You can check the output `aws lambda get-function-configuration --function-name <yourFunctioName>` and this works.
9898
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.
9999

100100
### Node
101101
```
102+
provider:
103+
104+
# other configuration
105+
region: <AWS_REGION>
106+
102107
environment:
103108
SENTRY_TRACES_SAMPLE_RATE: '1.0'
104-
SENTRY_DSN: '<your sentry dsn>'
109+
SENTRY_DSN: '<SENTRY_DSN>'
105110
NODE_OPTIONS: '-r @sentry/serverless/dist/awslambda-auto'
106-
107-
custom:
111+
112+
layersResource:
108113
layers:
109-
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:8
114+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:26
110115
# - arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryNodeServerlessSDK:latest
111116
112-
myHandler:
113-
handler: src/handlers/myHandler.handler
114-
layers: ${self:custom.layers}
117+
<your function name>:
118+
handler: <your lambda handler function path>
119+
layers: ${self:layersResource.layers}
115120
```
116121

117122
### Python
118123
```
124+
provider:
125+
126+
# other configuration
127+
region: <AWS_REGION>
128+
119129
environment:
120130
SENTRY_TRACES_SAMPLE_RATE: '1.0'
121-
SENTRY_DSN: '<your sentry dsn>'
122-
123-
custom:
131+
SENTRY_DSN: '<SENTRY_DSN>'
132+
133+
layersResource:
124134
layers:
125-
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryPythonServerlessSDK:3
135+
- arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryPythonServerlessSDK:6
126136
# - arn:aws:lambda:${self:provider.region}:943013980633:layer:SentryPythonServerlessSDK:latest
127137
128-
myHandler:
138+
<your function name>:
129139
handler: sentry_sdk.integrations.init_serverless_sdk.sentry_lambda_handler
130140
environment:
131-
SENTRY_INITIAL_HANDLER: 'src/handlers/myHandler.handler'
132-
layers: ${self:custom.layers}
141+
SENTRY_INITIAL_HANDLER: '<your lambda handler function path>'
142+
layers: ${self:layersResource.layers}
133143
```
134144

135145
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.
136-
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.
146+
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)