Skip to content

Commit 67ecf7f

Browse files
author
Florian Chazal
committed
doc: describe how to use layer in SAM example
1 parent 613c25a commit 67ecf7f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Diff for: examples/sam/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,41 @@ sam logs -n getAllItemsFunction --stack-name powertools-example --tail
150150

151151
You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html).
152152

153+
## Switch to Lambda Layer
154+
155+
This example bundle all your dependencies in a single JS file thanks to esbuild but you can switch the AWSLambdaPowertoolsTypeScript Layer by:
156+
1. specifying the right ARN in `Layers` list under the function's `Properties`
157+
1. instructing esbuild to not bundle `@aws-lambda-powertools` under the function `Metadata/BuildProperties`
158+
159+
Here is the diff of the current sam template leveraging `AWSLambdaPowertoolsTypeScript` layer:
160+
161+
```diff
162+
diff --git a/examples/sam/template.yaml b/examples/sa/template.yaml
163+
index 18a5662b..d4e90b55 100644
164+
--- a/examples/sam/template.yaml
165+
+++ b/examples/sam/template.yaml
166+
@@ -99,6 +99,8 @@ Resources:
167+
putItemFunction:
168+
Type: AWS::Serverless::Function
169+
Properties:
170+
+ Layers:
171+
+ - arn:aws:lambda:eu-west-3:094274105915:laye:AWSLambdaPowertoolsTypeScript:1
172+
Handler: src/put-item.putItemHandler
173+
Description: A simple example includes a HTTP ost method to add one item to a DynamoDB table.
174+
Policies:
175+
@@ -124,6 +126,11 @@ Resources:
176+
BuildMethod: esbuild
177+
BuildProperties:
178+
Minify: true
179+
+ External:
180+
+ - '@aws-lambda-powertools/commons'
181+
+ - '@aws-lambda-powertools/logger'
182+
+ - '@aws-lambda-powertools/metrics'
183+
+ - '@aws-lambda-powertools/tracer'
184+
Target: "es2020"
185+
Sourcemap: true,
186+
EntryPoints:
187+
```
153188

154189
## Cleanup
155190

0 commit comments

Comments
 (0)