Skip to content

Commit 9a82e7b

Browse files
committed
Merge remote-tracking branch 'origin/1177-feature-implement-appconfig-provider' into 1177-feature-implement-appconfig-provider
2 parents f36b06f + bdfc9b8 commit 9a82e7b

File tree

92 files changed

+22272
-25380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+22272
-25380
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.212.0/containers/javascript-node/.devcontainer/base.Dockerfile
2-
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 16-bullseye, 14-bullseye, 16-buster, 14-buster
3-
ARG VARIANT="16-bullseye"
2+
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
3+
ARG VARIANT="18-bullseye"
44
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
55

66
# This section to install additional OS packages.

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"name": "Node.js",
55
"build": {
66
"dockerfile": "Dockerfile",
7-
// Update 'VARIANT' to pick a Node version: 16, 14.
7+
// Update 'VARIANT' to pick a Node version: 18, 16, 14.
88
// Append -bullseye or -buster to pin to an OS version.
99
// Use -bullseye variants on local arm64/Apple Silicon.
1010
"args": {
11-
"VARIANT": "16-bullseye"
11+
"VARIANT": "18-bullseye"
1212
}
1313
},
1414
// Set *default* container specific settings.json values on container create.

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ body:
5858
attributes:
5959
label: AWS Lambda function runtime
6060
options:
61-
- 14.x
61+
- 18.x
6262
- 16.x
63+
- 14.x
6364
validations:
6465
required: true
6566
- type: dropdown

.github/workflows/make-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup NodeJS
2121
uses: actions/setup-node@v3
2222
with:
23-
node-version: "16"
23+
node-version: "18"
2424
cache: "npm"
2525
- name: Setup npm
2626
run: |
@@ -33,7 +33,7 @@ jobs:
3333
path: "./node_modules"
3434
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
3535
# if one of them changes the cache is invalidated/discarded
36-
key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
36+
key: 18-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
3737
- name: Build packages
3838
run: |
3939
npm run build -w packages/commons

.github/workflows/publish_layer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Setup Node.js
3535
uses: actions/setup-node@v3
3636
with:
37-
node-version: "16.12"
37+
node-version: "18"
3838
- name: Set release notes tag
3939
run: |
4040
RELEASE_INPUT=${{ inputs.latest_published_version }}

.github/workflows/reusable-publish-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Setup NodeJS
3939
uses: actions/setup-node@v3
4040
with:
41-
node-version: "16"
41+
node-version: "18"
4242
cache: "npm"
4343
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
4444
# if one of them changes the cache is invalidated/discarded
@@ -47,7 +47,7 @@ jobs:
4747
uses: actions/cache@v3
4848
with:
4949
path: "./node_modules"
50-
key: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
50+
key: 18-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
5151
- name: Install dependencies
5252
# We can skip the installation if there was a cache hit
5353
if: steps.cache-node-modules.outputs.cache-hit != 'true'

.github/workflows/reusable-run-linting-check-and-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
NODE_ENV: dev
1111
strategy:
1212
matrix:
13-
version: [14, 16]
13+
version: [14, 16, 18]
1414
fail-fast: false
1515
steps:
1616
- name: Checkout code

.github/workflows/reusable_deploy_layer_stack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
- name: Setup Node.js
6363
uses: actions/setup-node@v3
6464
with:
65-
node-version: "16.12"
65+
node-version: "18"
6666
- name: install cdk and deps
6767
run: |
6868
npm install -g [email protected]

.github/workflows/run-e2e-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
package: [logger, metrics, tracer]
23-
version: [14, 16]
23+
version: [14, 16, 18]
2424
fail-fast: false
2525
steps:
2626
- name: Checkout Repo
@@ -70,7 +70,7 @@ jobs:
7070
strategy:
7171
fail-fast: false
7272
matrix:
73-
version: [14, 16]
73+
version: [14, 16, 18]
7474
steps:
7575
- name: Checkout Repo
7676
uses: actions/checkout@v3
@@ -93,8 +93,8 @@ jobs:
9393
- name: Setup NodeJS
9494
uses: actions/setup-node@v3
9595
with:
96-
# Always use version 16 as we use TypeScript target es2020
97-
node-version: 16
96+
# Always use version 18
97+
node-version: 18
9898
- name: Setup npm
9999
run: npm i -g npm@next-8
100100
- name: "Configure AWS credentials"

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/gallium
1+
lts/hydrogen

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ The alternative is to use a Cloud IDE like [Gitpod](https://www.gitpod.io/) or [
7171

7272
The following tools need to be installed on your system prior to starting working on a pull request:
7373

74-
- [Node.js >= 16.x](https://nodejs.org/download/release/latest-v16.x/)
74+
- [Node.js >= 18.x](https://nodejs.org/download/release/latest-v18.x/)
7575
- We recommend using a version in [Active LTS](https://nodejs.org/en/about/releases/)
7676
- If you use [nvm](https://github.com/nvm-sh/nvm#nvmrc) or [fnm](https://github.com/Schniz/fnm) you can install the latest LTS version with `nvm use` or `fnm use` respectively. Both will use the `.nvmrc` file in the project's root.
7777
- [npm 8.x](https://www.npmjs.com/)
7878
- After installing Node.js, you can install `npm` with `npm install -g npm@next-8`
79-
- [AWS SAM CLI >= 1.49.0](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
79+
- [AWS SAM CLI >= 1.65.0](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
8080
- AWS SAM CLI is a command line interface for AWS Serverless Application Model (SAM), it's used in one of the examples, and it's part of the pre-push hook.
8181
- [Docker](https://docs.docker.com/get-docker/)
8282
- Docker is used to build documentation and Layer.
8383

8484
First, [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the repository, and then run the following commands to clone and initialize the repository locally.
8585

8686
> **Note**
87-
> In order for the commands below to work you need Node.js `16.x` and npm `8.x`
87+
> In order for the commands below to work you need Node.js `18.x` and npm `8.x`
8888
8989
```console
9090
git clone https://github.com/{your-account}/aws-lambda-powertools-typescript.git
@@ -272,7 +272,7 @@ Contributions via pull requests are much appreciated.
272272

273273
### Summary
274274

275-
* This project uses `node@16.x` and `[email protected]` for development (see [Setup](#setup)).
275+
* This project uses `node@18.x` and `[email protected]` for development (see [Setup](#setup)).
276276
* Before opening a Pull Request, please find the existing related issue or open a new one to discuss the proposed changes. A PR without a related issue or discussion has a high risk of being rejected. We are very appreciative and thankful for your time and efforts, and we want to make sure they are not wasted.
277277
* After your proposal has been reviewed and accepted by at least one of the project's maintainers, you can submit a pull request.
278278
* When opening a PR, make sure to follow the checklist inside the pull request template.

examples/cdk/README.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
This is a deployable CDK app that deploys AWS Lambda functions as part of a CloudFormation stack. These Lambda functions use the utilities made available as part of AWS Lambda Powertools for TypeScript to demonstrate their usage.
44

5-
You will need to have a valid AWS Account in order to deploy these resources. These resources may incur costs to your AWS Account. The cost from **some services** are covered by the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) but not all of them. If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
5+
> **Note**
6+
> You will need to have a valid AWS Account in order to deploy these resources. These resources may incur costs to your AWS Account. The cost from **some services** are covered by the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) but not all of them. If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
67
7-
The example functions, located in the `src` folder, are invoked automatically, twice, when deployed using the CDK construct defined in `src/example-function.ts`. The first invocation demonstrates the effect on logs/metrics/annotations when the Lambda function has a cold start, and the latter without a cold start.
8+
The example functions, located in the `functions` folder, are frontend by a REST API that is deployed using AWS API Gateway.
9+
10+
The API has three endpoints:
11+
12+
* `POST /` - Adds an item to the DynamoDB table
13+
* `GET /` - Retrieves all items from the DynamoDB table
14+
* `GET /{id}` - Retrieves a specific item from the DynamoDB table
815

916
## Deploying the stack
1017

@@ -14,10 +21,59 @@ The example functions, located in the `src` folder, are invoked automatically, t
1421

1522
Note: Prior to deploying you may need to run `cdk bootstrap aws://<YOU_AWS_ACCOUNT_ID>/<AWS_REGION> --profile <YOUR_AWS_PROFILE>` if you have not already bootstrapped your account for CDK.
1623

17-
## Viewing Utility Outputs
24+
> **Note**
25+
> You can find your API Gateway Endpoint URL in the output values displayed after deployment.
26+
27+
## Execute the functions via API Gateway
28+
29+
Use the API Gateway Endpoint URL from the output values to execute the functions. First, let's add two items to the DynamoDB Table by running:
30+
31+
```bash
32+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myfirstitem","name":"Some Name for the first item"}' https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/
33+
curl -XPOST --header 'Content-Type: application/json' --data '{"id":"myseconditem","name":"Some Name for the second item"}' https://randomid1245.execute-api.eu-central-1.amazonaws.com/prod/
34+
````
35+
36+
Now, let's retrieve all items by running:
37+
38+
```sh
39+
curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/
40+
```
41+
42+
And finally, let's retrieve a specific item by running:
43+
```bash
44+
curl -XGET https://randomid12345.execute-api.eu-central-1.amazonaws.com/prod/myseconditem/
45+
```
46+
47+
## Observe the outputs in AWS CloudWatch & X-Ray
48+
49+
### CloudWatch
50+
51+
If we check the logs in CloudWatch, we can see that the logs are structured like this
52+
```
53+
2022-04-26T17:00:23.808Z e8a51294-6c6a-414c-9777-6b0f24d8739b DEBUG
54+
{
55+
"level": "DEBUG",
56+
"message": "retrieved items: 0",
57+
"service": "getAllItems",
58+
"timestamp": "2022-04-26T17:00:23.808Z",
59+
"awsRequestId": "e8a51294-6c6a-414c-9777-6b0f24d8739b"
60+
}
61+
```
62+
63+
By having structured logs like this, we can easily search and analyse them in [CloudWatch Logs Insight](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html). Run the following query to get all messages for a specific `awsRequestId`:
64+
65+
````
66+
filter awsRequestId="bcd50969-3a55-49b6-a997-91798b3f133a"
67+
| fields timestamp, message
68+
````
69+
### AWS X-Ray
70+
71+
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.
72+
73+
## Cleanup
1874
19-
All utility outputs can be viewed in the Amazon CloudWatch console.
75+
To delete the sample application that you created, run the command below while in the `examples/sam` directory:
2076
21-
* `Logger` output can be found in Logs > Log groups
22-
* `Metrics` output can be found in Metrics > All metrics > CdkExample
23-
* `Tracer` output can be found in X-Ray traces > Traces
77+
```bash
78+
cdk delete
79+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Get the DynamoDB table name from environment variables
2+
const tableName = process.env.SAMPLE_TABLE;
3+
4+
export {
5+
tableName
6+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2+
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3+
import { tracer } from './powertools';
4+
5+
// Create DynamoDB Client and patch it for tracing
6+
const ddbClient = tracer.captureAWSv3Client(new DynamoDBClient({}));
7+
8+
const marshallOptions = {
9+
// Whether to automatically convert empty strings, blobs, and sets to `null`.
10+
convertEmptyValues: false, // false, by default.
11+
// Whether to remove undefined values while marshalling.
12+
removeUndefinedValues: false, // false, by default.
13+
// Whether to convert typeof object to map attribute.
14+
convertClassInstanceToMap: false, // false, by default.
15+
};
16+
17+
const unmarshallOptions = {
18+
// Whether to return numbers as a string instead of converting them to native JavaScript numbers.
19+
wrapNumbers: false, // false, by default.
20+
};
21+
22+
const translateConfig = { marshallOptions, unmarshallOptions };
23+
24+
// Create the DynamoDB Document client.
25+
const docClient = DynamoDBDocumentClient.from(ddbClient, translateConfig);
26+
27+
export {
28+
docClient
29+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Logger } from '@aws-lambda-powertools/logger';
2+
import { Metrics } from '@aws-lambda-powertools/metrics';
3+
import { Tracer } from '@aws-lambda-powertools/tracer';
4+
5+
const awsLambdaPowertoolsVersion = '1.5.0';
6+
7+
const defaultValues = {
8+
region: process.env.AWS_REGION || 'N/A',
9+
executionEnv: process.env.AWS_EXECUTION_ENV || 'N/A'
10+
};
11+
12+
const logger = new Logger({
13+
persistentLogAttributes: {
14+
...defaultValues,
15+
logger: {
16+
name: '@aws-lambda-powertools/logger',
17+
version: awsLambdaPowertoolsVersion,
18+
}
19+
},
20+
});
21+
22+
const metrics = new Metrics({
23+
defaultDimensions: defaultValues
24+
});
25+
26+
const tracer = new Tracer();
27+
28+
export {
29+
logger,
30+
metrics,
31+
tracer
32+
};

0 commit comments

Comments
 (0)