Skip to content

Commit f54e1b5

Browse files
committed
merged update from v2
2 parents 2b3317f + 3a072aa commit f54e1b5

File tree

349 files changed

+5655
-7551
lines changed

Some content is hidden

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

349 files changed

+5655
-7551
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Bug report
22
description: Report a reproducible bug to help us improve
3-
title: "Bug: TITLE"
4-
labels: ["type/bug", "triage"]
5-
projects: ["aws-powertools/7"]
3+
title: 'Bug: TITLE'
4+
labels: ['type/bug', 'triage']
5+
projects: ['aws-powertools/7']
66
body:
77
- type: markdown
88
attributes:
99
value: |
1010
Thank you for submitting a bug report. Before you start, make sure that [the bug hasn't been reported already](https://github.com/aws-powertools/powertools-lambda-typescript/issues).
11-
11+
1212
Please add as much information as possible to help us reproduce, and remove any potential sensitive data.
1313
- type: textarea
1414
id: expected_behaviour
@@ -58,7 +58,7 @@ body:
5858
id: version
5959
attributes:
6060
label: Powertools for AWS Lambda (TypeScript) version
61-
placeholder: "latest, 1.3.0"
61+
placeholder: 'latest, 2.0.0'
6262
value: latest
6363
validations:
6464
required: true
@@ -67,9 +67,9 @@ body:
6767
attributes:
6868
label: AWS Lambda function runtime
6969
options:
70+
- 20.x
7071
- 18.x
7172
- 16.x
72-
- 14.x
7373
validations:
7474
required: true
7575
- type: dropdown
@@ -95,4 +95,4 @@ body:
9595
value: |
9696
---
9797
98-
**Disclaimer**: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.
98+
**Disclaimer**: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.

.github/actions/cached-node-modules/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
nodeVersion: # id of input
55
description: 'Node.js version to use in the cache key'
66
default: '18'
7+
build:
8+
description: 'Whether to build the packages or not'
9+
default: 'true'
710
outputs:
811
cache-hit:
912
description: "Whether the cache was hit or not"
@@ -28,8 +31,8 @@ runs:
2831
run: npm ci
2932
shell: bash
3033
- name: Build packages
31-
# Regardless of whether the cache was hit or not, we need to build the packages.
32-
#
34+
# Regardless of whether the cache was hit or not, we need to build the packages, unless the caller says otherwise
35+
if: inputs.build == 'true'
3336
# We build the shared package first, then the others in parallel to speed up the process
3437
# even though we could just run `npm run build` in the root folder and build them in
3538
# sequence, but still in the correct order.

.github/scripts/release_patch_package_json.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ if (process.argv.length < 3) {
1717
}
1818
const basePath = resolve(process.argv[2]);
1919
const packageJsonPath = join(basePath, 'package.json');
20-
const alphaPackages = [];
20+
const alphaPackages = [
21+
'@aws-lambda-powertools/batch',
22+
'@aws-lambda-powertools/commons',
23+
'@aws-lambda-powertools/idempotency',
24+
'@aws-lambda-powertools/logger',
25+
'@aws-lambda-powertools/metrics',
26+
'@aws-lambda-powertools/parameters',
27+
'@aws-lambda-powertools/tracer',
28+
];
2129
const betaPackages = [];
2230

2331
(() => {
@@ -44,12 +52,22 @@ const betaPackages = [];
4452
types,
4553
files,
4654
private,
55+
type,
4756
} = pkgJson;
4857

4958
let version = originalVersion;
5059
// If the package is an alpha or beta package, update the version number to include a suffix
5160
if (alphaPackages.includes(name)) {
52-
version = `${version}-alpha`;
61+
const iteration = JSON.parse(
62+
readFileSync(resolve('..', '..', 'v2.json'), 'utf8')
63+
).iteration;
64+
version = `${version}-alpha.${iteration}`;
65+
dependencies &&
66+
Object.entries(dependencies).forEach(([dependencyName, version]) => {
67+
if (alphaPackages.includes(dependencyName)) {
68+
dependencies[dependencyName] = `${version}-alpha.${iteration}`;
69+
}
70+
});
5371
} else if (betaPackages.includes(name)) {
5472
version = `${version}-beta`;
5573
}
@@ -71,6 +89,7 @@ const betaPackages = [];
7189
main,
7290
types,
7391
files,
92+
type,
7493
};
7594

7695
// Not all utilities have these fields, so only add them if they exist to avoid

.github/workflows/make-v2-release.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
2929
- name: Setup dependencies
3030
uses: ./.github/actions/cached-node-modules
31+
with:
32+
# We don't build the packages here as we want to version them first
33+
build: false
3134
- name: Version
3235
run: |
3336
# Version all packages to next major version (2.0.0) without pushing to git, generating changelog or running commit hooks
@@ -36,17 +39,17 @@ jobs:
3639
- name: Set alpha iteration
3740
run: |
3841
# Get the current alpha version from npm i.e 2.0.0-alpha.0 -> 0, 2.0.0-alpha.1 -> 1 (default to -1 if no alpha versions exist = first pre-release)
39-
ITERATION=$(npm show @aws-lambda-powertools/commons time --json | jq -r 'to_entries | map(select(.key | startswith("2.0.0-alpha"))) | sort_by(.key) | last | .key // "-1"')
42+
ITERATION=$(npm show @aws-lambda-powertools/commons time --json | jq -r 'to_entries | map(select(.key | startswith("2.0.0-alpha"))) | sort_by(.key) | last | .key // "-1"' | cut -d '.' -f 4)
4043
# Write the new version to the file
4144
echo "{ \"iteration\": $((ITERATION + 1)) }" > v2.json
4245
- name: Increment version in UA
4346
run: |
4447
# Increment the version in the UA
45-
echo "// this file is auto generated, do not modify\nexport const PT_VERSION = '2.0.0-alpha.$(jq -r '.iteration' v2.json)';" > packages/commons/src/version.ts
48+
echo -e "// this file is auto generated, do not modify\nexport const PT_VERSION = '2.0.0-alpha.$(jq -r '.iteration' v2.json)';" > packages/commons/src/version.ts
4649
- name: Build
4750
run: |
51+
npm run build -w packages/commons &
4852
npm run build -w packages/batch \
49-
-w packages/commons \
5053
-w packages/idempotency \
5154
-w packages/logger \
5255
-w packages/metrics \

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ jobs:
7878
run: |
7979
rm -rf site
8080
mkdocs build
81-
mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages
81+
# mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages
8282
# Set latest version as a default
83-
mike set-default latest --branch backup-gh-pages
83+
# mike set-default latest --branch backup-gh-pages
8484
- name: Build API docs
8585
run: |
8686
rm -rf api

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
NODE_ENV: dev
1111
strategy:
1212
matrix:
13-
version: [14, 16, 18]
13+
version: [16, 18]
1414
fail-fast: false
1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
17+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
1818
- name: Setup NodeJS
1919
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
2020
with:
2121
node-version: ${{ matrix.version }}
22-
cache: "npm"
22+
cache: 'npm'
2323
- name: Setup dependencies
2424
uses: ./.github/actions/cached-node-modules
2525
with:
@@ -34,19 +34,19 @@ jobs:
3434
NODE_ENV: dev
3535
strategy:
3636
matrix:
37-
example: ["sam", "cdk"]
37+
example: ['sam', 'cdk']
3838
fail-fast: false
3939
defaults:
4040
run:
4141
working-directory: examples/${{ matrix.example }}
4242
steps:
4343
- name: Checkout code
44-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
44+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
4545
- name: Setup NodeJS
4646
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
4747
with:
4848
node-version: 18
49-
cache: "npm"
49+
cache: 'npm'
5050
- name: Setup dependencies
5151
uses: ./.github/actions/cached-node-modules
5252
- name: Run linting
@@ -59,12 +59,12 @@ jobs:
5959
NODE_ENV: dev
6060
steps:
6161
- name: Checkout code
62-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
62+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
6363
- name: Setup NodeJS
6464
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
6565
with:
6666
node-version: 18
67-
cache: "npm"
67+
cache: 'npm'
6868
- name: Setup dependencies
6969
uses: ./.github/actions/cached-node-modules
7070
- name: Run linting
@@ -77,12 +77,12 @@ jobs:
7777
NODE_ENV: dev
7878
steps:
7979
- name: Checkout code
80-
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
80+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
8181
- name: Setup NodeJS
8282
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
8383
with:
8484
node-version: 18
85-
cache: "npm"
85+
cache: 'npm'
8686
- name: Setup dependencies
8787
uses: ./.github/actions/cached-node-modules
8888
- name: Run linting

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
packages/parameters,
2929
packages/idempotency,
3030
]
31-
version: [14, 16, 18]
31+
version: [16, 18]
3232
arch: [x86_64, arm64]
3333
fail-fast: false
3434
steps:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ site
4949
tmp
5050

5151
# TS build files
52-
tsconfig.tsbuildinfo
52+
*.tsbuildinfo

MAINTAINERS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
> [!IMPORTANT]
2-
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/
2+
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mike==1.1.2
2-
mkdocs-material==9.3.2
2+
mkdocs-material==9.4.6
33
mkdocs-git-revision-date-plugin==0.3.2
44
mkdocs-exclude==1.0.2

docs/snippets/logger/bringYourOwnFormatterClass.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import {
33
LogAttributes,
44
UnformattedAttributes,
55
} from '@aws-lambda-powertools/logger/lib/types';
6+
import { LogItem } from '@aws-lambda-powertools/logger/lib/log';
67

78
// Replace this line with your own type
89
type MyCompanyLog = LogAttributes;
910

1011
class MyCompanyLogFormatter extends LogFormatter {
11-
public formatAttributes(attributes: UnformattedAttributes): MyCompanyLog {
12-
return {
12+
public formatAttributes(
13+
attributes: UnformattedAttributes,
14+
additionalLogAttributes: LogAttributes
15+
): LogItem {
16+
const baseAttributes: MyCompanyLog = {
1317
message: attributes.message,
1418
service: attributes.serviceName,
1519
environment: attributes.environment,
@@ -31,6 +35,11 @@ class MyCompanyLogFormatter extends LogFormatter {
3135
sampleRateValue: attributes.sampleRateValue,
3236
},
3337
};
38+
39+
const logItem = new LogItem({ attributes: baseAttributes });
40+
logItem.addAttributes(additionalLogAttributes); // add any attributes not explicitly defined
41+
42+
return logItem;
3443
}
3544
}
3645

docs/snippets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "1.9.0",
3+
"version": "1.14.0",
44
"description": "A collection code snippets for the Powertools for AWS Lambda (TypeScript) docs",
55
"author": {
66
"name": "Amazon Web Services",

docs/upgrade.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,14 @@ title: Upgrade guide
33
description: Guide to update between major Powertools for AWS Lambda (TypeScript) versions
44
---
55

6+
## Migrate to v2 from v1
7+
8+
This release includes some breaking changes, please take some time to review this guide to make your transition to v2 as smooth as possible.
9+
10+
### Quick summary
11+
612
!!! warning
7-
This guide is a work in progress. We'll update it as we get closer to the 2.0 release. If you have any questions, or want to follow the progress, please join the discussion on the [GitHub issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/1714).
13+
This guide is a work in progress. We'll update it as we get closer to the 2.0 release. If you have any questions, or want to follow the progress, please join the discussion on the [GitHub issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/1714).
14+
15+
| Area | Change | Code change required |
16+
| ---- | ------ | -------------------- |

examples/cdk/functions/common/powertools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
22
import { Metrics } from '@aws-lambda-powertools/metrics';
33
import { Tracer } from '@aws-lambda-powertools/tracer';
4-
import { PT_VERSION } from '@aws-lambda-powertools/commons/lib/version';
4+
import { PT_VERSION } from '@aws-lambda-powertools/commons';
55

66
const defaultValues = {
77
region: process.env.AWS_REGION || 'N/A',

examples/cdk/functions/get-all-items.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { injectLambdaContext } from '@aws-lambda-powertools/logger';
2-
import { logMetrics } from '@aws-lambda-powertools/metrics';
3-
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer';
1+
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
2+
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
3+
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
44
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
55
import middy from '@middy/core';
66
import {

examples/cdk/functions/get-by-id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LambdaInterface } from '@aws-lambda-powertools/commons';
1+
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
22
import { GetCommand } from '@aws-sdk/lib-dynamodb';
33
import {
44
APIGatewayProxyEvent,

examples/cdk/functions/uuid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { randomUUID } from 'node:crypto';
22

3-
exports.handler = async (_event) => {
3+
exports.handler = async () => {
44
return {
55
statusCode: 200,
66
body: JSON.stringify(randomUUID()),

examples/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
"phin": "^3.7.0",
5050
"source-map-support": "^0.5.21"
5151
}
52-
}
52+
}

examples/sam/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
"esbuild": "^0.19.3",
4242
"phin": "^3.7.0"
4343
}
44-
}
44+
}

examples/sam/src/common/powertools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
22
import { Metrics } from '@aws-lambda-powertools/metrics';
33
import { Tracer } from '@aws-lambda-powertools/tracer';
4-
import { PT_VERSION } from '@aws-lambda-powertools/commons/lib/version';
4+
import { PT_VERSION } from '@aws-lambda-powertools/commons';
55

66
const defaultValues = {
77
region: process.env.AWS_REGION || 'N/A',

examples/sam/src/get-all-items.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
import middy from '@middy/core';
77
import { tableName } from './common/constants';
88
import { logger, tracer, metrics } from './common/powertools';
9-
import { logMetrics } from '@aws-lambda-powertools/metrics';
10-
import { injectLambdaContext } from '@aws-lambda-powertools/logger';
11-
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer';
9+
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
10+
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
11+
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
1212
import { docClient } from './common/dynamodb-client';
1313
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
1414
import { getUuid } from './common/getUuid';

examples/sam/src/get-by-id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LambdaInterface } from '@aws-lambda-powertools/commons';
1+
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
22
import { GetCommand } from '@aws-sdk/lib-dynamodb';
33
import {
44
APIGatewayProxyEvent,

0 commit comments

Comments
 (0)