Skip to content

Commit 6b008c2

Browse files
authored
Merge branch 'main' into improv/metrics-no-override-function-name
2 parents 2378cb2 + 80c7eb9 commit 6b008c2

File tree

93 files changed

+1994
-2190
lines changed

Some content is hidden

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

93 files changed

+1994
-2190
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.212.0/containers/javascript-node/.devcontainer/base.Dockerfile
2-
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node@sha256:896bfba10582c9239d1c36bab53b80af06253019f62b846fa440ee643ca63eb1
2+
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node@sha256:78fda8c284dd3247d7385d55974e278314233f1acc130ba89757703137dbda45
33

44
# Install fnm to manage Node.js versions
55
RUN curl -fsSL https://fnm.vercel.app/install -o /tmp/install \

.github/scripts/get_pr_info.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/bootstrap_region.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
mask-aws-account-id: true
8989
- id: go-setup
9090
name: Setup Go
91-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
91+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
9292
with:
9393
go-version: '>=1.23.0'
9494
- id: go-env

.github/workflows/layer_balance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
mask-aws-account-id: true
5151
- id: go-setup
5252
name: Setup Go
53-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
53+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
5454
with:
5555
go-version: '>=1.23.0'
5656
- id: go-env

.github/workflows/ossf_scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343

4444
# Upload the results to GitHub's code scanning dashboard.
4545
- name: "Upload to code-scanning"
46-
uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
46+
uses: github/codeql-action/upload-sarif@5f8171a638ada777af81d42b55959a643bb29017 # v3.28.12
4747
with:
4848
sarif_file: results.sarif

.github/workflows/publish_layer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
with:
9898
ref: ${{ github.sha }}
9999
- name: Download CDK layer artifacts
100-
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
100+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
101101
with:
102102
path: cdk-layer-stack
103103
pattern: cdk-layer-stack-* # merge all Layer artifacts created per region earlier (reusable_deploy_layer_stack.yml; step "Save Layer ARN artifact")

.github/workflows/reusable_deploy_layer_stack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Setup dependencies
8282
uses: aws-powertools/actions/.github/actions/cached-node-modules@29979bc5339bf54f76a11ac36ff67701986bb0f0
8383
- name: Download artifact
84-
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
84+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
8585
with:
8686
name: ${{ inputs.artifact-name }}
8787
- name: Unzip artifact

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ jobs:
1717
env:
1818
NODE_ENV: dev
1919
PR_NUMBER: ${{ inputs.prNumber }}
20+
GH_TOKEN: ${{ github.token }}
2021
permissions:
2122
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
2223
contents: read
2324
strategy:
24-
max-parallel: 30
25+
max-parallel: 25
2526
matrix:
2627
package:
2728
[
28-
layers,
29+
packages/idempotency,
2930
packages/logger,
3031
packages/metrics,
31-
packages/tracer,
3232
packages/parameters,
33-
packages/idempotency,
33+
packages/tracer,
34+
layers,
3435
]
3536
version: [18, 20, 22]
3637
arch: [x86_64, arm64]
@@ -42,11 +43,14 @@ jobs:
4243
- name: Extract PR details
4344
id: extract_PR_details
4445
if: ${{ inputs.prNumber != '' }}
45-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
46-
with:
47-
script: |
48-
const script = require('.github/scripts/get_pr_info.js');
49-
await script({github, context, core});
46+
run: |
47+
# Get the PR number from the input
48+
pr_number=${{ inputs.prNumber }}
49+
# Get the headSHA of the PR
50+
head_sha=$(gh pr view $pr_number --json headRefOid -q '.headRefOid')
51+
# Set the headSHA as an output variable
52+
echo "headSHA=$head_sha" >> $GITHUB_OUTPUT
53+
echo "headSHA=$head_sha"
5054
# Only if a PR Number was passed and the headSHA of the PR extracted,
5155
# we checkout the PR at that point in time
5256
- name: Checkout PR code
@@ -75,4 +79,4 @@ jobs:
7579
ARCH: ${{ matrix.arch }}
7680
JSII_SILENCE_WARNING_DEPRECATED_NODE_VERSION: true
7781
RUNNER_DEBUG: ${{ env.RUNNER_DEBUG }}
78-
run: npm run test:e2e -w ${{ matrix.package }}
82+
run: npm run test:e2e -w ${{ matrix.package }}

docs/core/logger.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,16 +767,19 @@ sequenceDiagram
767767
4. **What happens if the log buffer reaches its maximum size?**
768768
Older logs are removed from the buffer to make room for new logs. This means that if the buffer is full, you may lose some logs if they are not flushed before the buffer reaches its maximum size. When this happens, we emit a warning when flushing the buffer to indicate that some logs have been dropped.
769769

770-
5. **What timestamp is used when I flush the logs?**
770+
5. **How is the log size of a log line calculated?**
771+
The log size is calculated based on the size of the stringified log line in bytes. This includes the size of the log message, the size of any additional keys, and the size of the timestamp.
772+
773+
6. **What timestamp is used when I flush the logs?**
771774
The timestamp preserves the original time when the log record was created. If you create a log record at 11:00:10 and flush it at 11:00:25, the log line will retain its original timestamp of 11:00:10.
772775

773-
6. **What happens if I try to add a log line that is bigger than max buffer size?**
776+
7. **What happens if I try to add a log line that is bigger than max buffer size?**
774777
The log will be emitted directly to standard output and not buffered. When this happens, we emit a warning to indicate that the log line was too big to be buffered.
775778

776-
7. **What happens if Lambda times out without flushing the buffer?**
779+
8. **What happens if Lambda times out without flushing the buffer?**
777780
Logs that are still in the buffer will be lost. If you are using the log buffer to log asynchronously, you should ensure that the buffer is flushed before the Lambda function times out. You can do this by calling the `logger.flushBuffer()` method at the end of your Lambda function.
778781

779-
8. **Do child loggers inherit the buffer?**
782+
9. **Do child loggers inherit the buffer?**
780783
No, child loggers do not inherit the buffer from their parent logger but only the buffer configuration. This means that if you create a child logger, it will have its own buffer and will not share the buffer with the parent logger.
781784

782785
### Reordering log keys position

docs/utilities/parser.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Both are also able to parse either an object or JSON string as an input.
4444
Be cautious when using multiple decorators that expect event to have a specific structure, the order of evaluation for decorators is from bottom to top.
4545

4646
=== "Middy middleware"
47-
```typescript hl_lines="34"
47+
```typescript hl_lines="22"
4848
--8<-- "examples/snippets/parser/middy.ts"
4949
```
5050

@@ -157,7 +157,7 @@ If you want to extend a schema and transform a JSON stringified payload to an ob
157157
If you want to parse a DynamoDB stream event with unmarshalling, you can use the helper function `DynamoDBMarshalled`:
158158

159159
=== "DynamoDBStreamSchema with DynamoDBMarshalled"
160-
```typescript hl_lines="17"
160+
```typescript hl_lines="18"
161161
--8<-- "examples/snippets/parser/extendDynamoDBStreamSchema.ts"
162162
```
163163

@@ -180,12 +180,12 @@ Envelopes can be used via envelope parameter available in middy and decorator.
180180
Here's an example of parsing a custom schema in an event coming from EventBridge, where all you want is what's inside the detail key.
181181

182182
=== "Middy middleware"
183-
```typescript hl_lines="5 36"
183+
```typescript hl_lines="23"
184184
--8<-- "examples/snippets/parser/envelopeMiddy.ts"
185185
```
186186

187187
=== "Decorator"
188-
```typescript hl_lines="5 26 30"
188+
```typescript hl_lines="26"
189189
--8<-- "examples/snippets/parser/envelopeDecorator.ts"
190190
```
191191

@@ -230,26 +230,24 @@ The `ParsedResult` object will have `success`, `data`, or `error` and `original
230230
If the parsing is successful, the `data` field will contain the parsed event, otherwise you can access the `error` field and the `originalEvent` to handle the error and recover the original event.
231231

232232
=== "Middy middleware"
233-
```typescript hl_lines="32 35 38 39 44"
233+
```typescript hl_lines="23 28 32-33"
234234
--8<-- "examples/snippets/parser/safeParseMiddy.ts"
235235
```
236236

237237
1. Use `safeParse` option to parse the event without throwing an error
238-
2. Check if the result is successful or not and handle the error accordingly
239-
3. Use `data` to access the parsed event
240-
4. Use `error` to handle the error message
241-
5. Use `originalEvent` to get the original event and recover
238+
2. Use `data` to access the parsed event when successful
239+
3. Use `error` to handle the error message
240+
4. Use `originalEvent` to get the original event and recover
242241

243242
=== "Decorator"
244-
```typescript hl_lines="29 35 37 40 41"
243+
```typescript hl_lines="33 41 45-46"
245244
--8<-- "examples/snippets/parser/safeParseDecorator.ts"
246245
```
247246

248247
1. Use `safeParse` option to parse the event without throwing an error
249-
2. Check if the result is successful or not and handle the error accordingly
250-
3. Use `data` to access the parsed event
251-
4. Use `error` to handle the error message
252-
5. Use `originalEvent` to get the original event and recover
248+
2. Use `data` to access the parsed event when successful
249+
3. Use `error` to handle the error message
250+
4. Use `originalEvent` to get the original event and recover
253251

254252
## Manual parsing
255253

@@ -316,7 +314,7 @@ If you are you use middy middleware, you don't need to do this.
316314

317315
=== "handlerDecorator.test.ts"
318316

319-
```typescript hl_lines="26"
317+
```typescript hl_lines="27"
320318
--8<-- "examples/snippets/parser/unitTestDecorator.ts"
321319
```
322320

@@ -338,7 +336,7 @@ This also works when using `safeParse` option.
338336

339337
=== "handlerSafeParse.test.ts"
340338

341-
```typescript hl_lines="21-29 35 45"
339+
```typescript hl_lines="21-30 36 46"
342340
--8<-- "examples/snippets/parser/unitTestSafeParse.ts"
343341
```
344342

examples/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@middy/core": "^4.7.0",
5050
"@types/aws-lambda": "^8.10.147",
5151
"@types/node": "22.13.10",
52-
"aws-cdk": "^2.1004.0",
52+
"aws-cdk": "^2.1005.0",
5353
"constructs": "^10.4.2",
5454
"esbuild": "^0.25.1",
5555
"typescript": "^5.8.2"

examples/snippets/parser/envelopeDecorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
22
import { Logger } from '@aws-lambda-powertools/logger';
33
import { parser } from '@aws-lambda-powertools/parser';
4-
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
4+
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
55
import type { Context } from 'aws-lambda';
66
import { z } from 'zod';
77

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
2-
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
2+
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
33
import { parser } from '@aws-lambda-powertools/parser/middleware';
44
import middy from '@middy/core';
5-
import type { Context } from 'aws-lambda';
65
import { z } from 'zod';
76

87
const logger = new Logger();
@@ -20,18 +19,11 @@ const orderSchema = z.object({
2019
optionalField: z.string().optional(),
2120
});
2221

23-
type Order = z.infer<typeof orderSchema>;
24-
25-
const lambdaHandler = async (
26-
event: Order,
27-
_context: Context
28-
): Promise<void> => {
29-
for (const item of event.items) {
30-
// item is parsed as OrderItem
31-
logger.info('Processing item', { item });
32-
}
33-
};
34-
35-
export const handler = middy(lambdaHandler).use(
36-
parser({ schema: orderSchema, envelope: EventBridgeEnvelope })
37-
);
22+
export const handler = middy()
23+
.use(parser({ schema: orderSchema, envelope: EventBridgeEnvelope }))
24+
.handler(async (event): Promise<void> => {
25+
for (const item of event.items) {
26+
// item is parsed as OrderItem
27+
logger.info('Processing item', { item });
28+
}
29+
});

examples/snippets/parser/extend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
22
import { Logger } from '@aws-lambda-powertools/logger';
33
import { parser } from '@aws-lambda-powertools/parser';
4-
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas';
4+
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge';
55
import type { Context } from 'aws-lambda';
66
import { z } from 'zod';
77

examples/snippets/parser/extendDynamoDBStreamSchema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DynamoDBMarshalled } from '@aws-lambda-powertools/parser/helpers/dynamodb';
22
import {
3+
DynamoDBStreamChangeRecordBase,
34
DynamoDBStreamRecord,
45
DynamoDBStreamSchema,
56
} from '@aws-lambda-powertools/parser/schemas/dynamodb';
@@ -13,7 +14,7 @@ const customSchema = z.object({
1314
const extendedSchema = DynamoDBStreamSchema.extend({
1415
Records: z.array(
1516
DynamoDBStreamRecord.extend({
16-
dynamodb: z.object({
17+
dynamodb: DynamoDBStreamChangeRecordBase.extend({
1718
NewImage: DynamoDBMarshalled(customSchema).optional(),
1819
}),
1920
})

examples/snippets/parser/handlerSafeParseDecorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
22
import { Logger } from '@aws-lambda-powertools/logger';
33
import { parser } from '@aws-lambda-powertools/parser';
4-
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
4+
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
55
import type {
66
EventBridgeEvent,
77
ParsedResult,

examples/snippets/parser/manual.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
2-
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
3-
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas';
2+
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
3+
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge';
44
import type { EventBridgeEvent } from '@aws-lambda-powertools/parser/types';
55
import type { Context } from 'aws-lambda';
66
import { z } from 'zod';

examples/snippets/parser/manualSafeParse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
2-
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes';
3-
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas';
2+
import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge';
3+
import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge';
44
import type { EventBridgeEvent } from '@aws-lambda-powertools/parser/types';
55
import type { Context } from 'aws-lambda';
66
import { z } from 'zod';

examples/snippets/parser/middy.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
22
import { parser } from '@aws-lambda-powertools/parser/middleware';
33
import middy from '@middy/core';
4-
import type { Context } from 'aws-lambda';
54
import { z } from 'zod';
65

76
const logger = new Logger();
@@ -19,18 +18,11 @@ const orderSchema = z.object({
1918
optionalField: z.string().optional(),
2019
});
2120

22-
type Order = z.infer<typeof orderSchema>;
23-
24-
const lambdaHandler = async (
25-
event: Order,
26-
_context: Context
27-
): Promise<void> => {
28-
for (const item of event.items) {
29-
// item is parsed as OrderItem
30-
logger.info('Processing item', { item });
31-
}
32-
};
33-
34-
export const handler = middy(lambdaHandler).use(
35-
parser({ schema: orderSchema })
36-
);
21+
export const handler = middy()
22+
.use(parser({ schema: orderSchema }))
23+
.handler(async (event): Promise<void> => {
24+
for (const item of event.items) {
25+
// item is parsed as OrderItem
26+
logger.info('Processing item', { item });
27+
}
28+
});

0 commit comments

Comments
 (0)