Skip to content

Commit a4134c4

Browse files
authored
docs: update sam example to nodejs18 (#1196)
1 parent 95b40d1 commit a4134c4

15 files changed

+973
-1303
lines changed

Diff for: examples/lambda-functions/tsconfig.json

-28
This file was deleted.

Diff for: examples/sam/README.md

+45-34
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ In addition to the [recommended setup for this project](https://github.com/awsla
3030
To build and deploy your application for the first time, run the following in your shell:
3131

3232
```bash
33-
sam build --beta-features
33+
sam build --beta-features
3434
sam deploy --guided
3535
```
3636

@@ -57,14 +57,15 @@ Now, let's retrieve all items by running:
5757
5858
```bash
5959
curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/
60-
````
60+
```
6161
6262
And finally, let's retrieve a specific item by running:
6363
```bash
64-
https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/myseconditem/
64+
curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/Prod/myseconditem/
6565
```
6666

6767
## Observe the outputs in AWS CloudWatch & X-Ray
68+
6869
### CloudWatch
6970

7071
If we check the logs in CloudWatch, we can see that the logs are structured like this
@@ -86,7 +87,10 @@ filter awsRequestId="bcd50969-3a55-49b6-a997-91798b3f133a"
8687
| fields timestamp, message
8788
````
8889
### AWS X-Ray
89-
As we have enabled tracing for our Lambda-Funtions, we can visit [AWS X-Ray Console](https://console.aws.amazon.com/xray/home#/traces/) and see [traces](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) and a [service map](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-using-xray-maps.html) for our application.
90+
91+
As we have enabled tracing for our Lambda-Funtions, you can visit [AWS CloudWatch Console](https://console.aws.amazon.com/cloudwatch/) and see [Traces](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces) and a [Service Map](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-using-xray-maps.html) for our application.
92+
93+
You can also use the AWS SAM CLI to retrieve traces by running `sam traces`.
9094
9195
## Use the SAM CLI to build and test locally
9296
@@ -138,42 +142,49 @@ You can find more information and examples about filtering Lambda function logs
138142

139143
## Switch to Lambda Layer
140144

141-
This example bundle all your dependencies in a single JS file thanks to esbuild but you can switch the AWSLambdaPowertoolsTypeScript Layer by:
142-
1. specifying the right ARN in `Layers` list under the function's `Properties`
143-
1. instructing esbuild to not bundle `@aws-lambda-powertools` under the function `Metadata/BuildProperties`
145+
In this example we are including AWS Lambda Powertools as a dependency in our function's `package.json`. This is the recommended approach for development and testing. However, for production, you can also use the AWS Lambda Powertools as a Lambda Layer.
144146

145-
Learn more about Lambda Layers [here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) and about the Lambda Powertools for TypeScript layers [here](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#lambda-layer).
147+
To start using the AWS Lambda Powertools as a Lambda Layer, you need to:
148+
1. Specify the Layer's ARN in `Layers` section under each function's `Properties` section
149+
2. Instruct `esbuild` to not bundle `@aws-lambda-powertools` under each function's `Metadata/BuildProperties` section
146150

147-
Here is the diff of the current sam template leveraging `AWSLambdaPowertoolsTypeScript` layer:
151+
To do so, open the `template.yaml` file, and **for each Lambda Function**, update the following sections:
152+
```diff
153+
Resources:
154+
putItemFunction:
155+
Type: AWS::Serverless::Function
156+
Properties:
157+
+ Layers:
158+
+ - arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScript:6
159+
Handler: src/put-item.putItemHandler
160+
Description: A simple example includes a HTTP ost method to add one item to a DynamoDB table.
161+
Policies:
162+
```
163+
164+
and:
148165

149166
```diff
150-
diff --git a/examples/sam/template.yaml b/examples/sa/template.yaml
151-
index 18a5662b..d4e90b55 100644
152-
--- a/examples/sam/template.yaml
153-
+++ b/examples/sam/template.yaml
154-
@@ -99,6 +99,8 @@ Resources:
155-
putItemFunction:
156-
Type: AWS::Serverless::Function
157-
Properties:
158-
+ Layers:
159-
+ - arn:aws:lambda:eu-west-3:094274105915:layer:AWSLambdaPowertoolsTypeScript:5
160-
Handler: src/put-item.putItemHandler
161-
Description: A simple example includes a HTTP ost method to add one item to a DynamoDB table.
162-
Policies:
163-
@@ -124,6 +126,11 @@ Resources:
164-
BuildMethod: esbuild
165-
BuildProperties:
166-
Minify: true
167-
+ External:
168-
+ - '@aws-lambda-powertools/commons'
169-
+ - '@aws-lambda-powertools/logger'
170-
+ - '@aws-lambda-powertools/metrics'
171-
+ - '@aws-lambda-powertools/tracer'
172-
Target: "es2020"
173-
Sourcemap: true,
174-
EntryPoints:
167+
Metadata:
168+
# Manage esbuild properties
169+
BuildMethod: esbuild
170+
BuildProperties:
171+
BuildMethod: esbuild
172+
BuildProperties:
173+
Minify: true
174+
Target: "ES2020"
175+
Sourcemap: true
176+
External:
177+
- "@aws-sdk/lib-dynamodb"
178+
- "@aws-sdk/client-dynamodb"
179+
+ - "@aws-lambda-powertools/commons"
180+
+ - "@aws-lambda-powertools/logger'
181+
+ - "@aws-lambda-powertools/metrics"
182+
+ - "@aws-lambda-powertools/tracer"
183+
EntryPoints:
175184
```
176185

186+
Learn more about Lambda Layers [here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) and about the Lambda Powertools for TypeScript layers [here](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/#lambda-layer).
187+
177188
## Cleanup
178189

179190
To delete the sample application that you created, run the command below while in the `examples/sam` directory:

0 commit comments

Comments
 (0)