Skip to content

Commit 5811df9

Browse files
authored
Merge branch 'main' into chore/remove_axios
2 parents 365da2c + fe92fef commit 5811df9

32 files changed

+733
-390
lines changed

.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@b7cec7526559c32f1616476ff32d17ba4c59b2d6 # v3.25.5
46+
uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6
4747
with:
4848
sarif_file: results.sarif

docs/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ regex==2023.10.3 \
421421
--hash=sha256:f4f2ca6df64cbdd27f27b34f35adb640b5d2d77264228554e68deda54456eb11 \
422422
--hash=sha256:fb02e4257376ae25c6dd95a5aec377f9b18c09be6ebdefa7ad209b9137b73d48
423423
# via mkdocs-material
424-
requests==2.31.0 \
425-
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
426-
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
424+
requests==2.32.0 \
425+
--hash=sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5 \
426+
--hash=sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8
427427
# via mkdocs-material
428428
six==1.16.0 \
429429
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \

docs/utilities/batch.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ Processing batches from SQS works in three stages:
113113

114114
=== "index.ts"
115115

116-
```typescript hl_lines="1-5 14 17 29-31"
116+
```typescript hl_lines="1-5 9 12 21-23"
117117
--8<--
118-
examples/snippets/batch/gettingStartedSQS.ts::16
119-
examples/snippets/batch/gettingStartedSQS.ts:18:29
120-
examples/snippets/batch/gettingStartedSQS.ts:31:34
118+
examples/snippets/batch/gettingStartedSQS.ts::11
119+
examples/snippets/batch/gettingStartedSQS.ts:13:21
120+
examples/snippets/batch/gettingStartedSQS.ts:23:25
121121
--8<--
122122
```
123123

@@ -144,7 +144,7 @@ Processing batches from SQS works in three stages:
144144
When using [SQS FIFO queues](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html){target="_blank"}, we will stop processing messages after the first failure, and return all failed and unprocessed messages in `batchItemFailures`.
145145
This helps preserve the ordering of messages in your queue.
146146

147-
```typescript hl_lines="1-4 13 28-30"
147+
```typescript hl_lines="1-4 8 20-22"
148148
--8<-- "examples/snippets/batch/gettingStartedSQSFifo.ts"
149149
```
150150

@@ -167,11 +167,11 @@ Processing batches from Kinesis works in three stages:
167167

168168
=== "index.ts"
169169

170-
```typescript hl_lines="1-5 14 17 27-29"
170+
```typescript hl_lines="1-5 9 12 19-21"
171171
--8<-- "examples/snippets/batch/gettingStartedKinesis.ts"
172172
```
173173

174-
1. **Step 1**. Creates a partial failure batch processor for Kinesis Data Streams. See [partial failure mechanics for details](#partial-failure-mechanics)
174+
1. Creates a partial failure batch processor for Kinesis Data Streams. See [partial failure mechanics for details](#partial-failure-mechanics)
175175

176176
=== "Sample response"
177177

@@ -200,11 +200,11 @@ Processing batches from DynamoDB Streams works in three stages:
200200

201201
=== "index.ts"
202202

203-
```typescript hl_lines="1-5 14 17 32-34"
203+
```typescript hl_lines="1-5 9 12 24-26"
204204
--8<-- "examples/snippets/batch/gettingStartedDynamoDBStreams.ts"
205205
```
206206

207-
1. **Step 1**. Creates a partial failure batch processor for DynamoDB Streams. See [partial failure mechanics for details](#partial-failure-mechanics)
207+
1. Creates a partial failure batch processor for DynamoDB Streams. See [partial failure mechanics for details](#partial-failure-mechanics)
208208

209209
=== "Sample response"
210210

@@ -226,17 +226,17 @@ By default, we catch any exception raised by your record handler function. This
226226

227227
=== "Sample error handling with custom exception"
228228

229-
```typescript hl_lines="30"
229+
```typescript hl_lines="25"
230230
--8<--
231-
examples/snippets/batch/gettingStartedErrorHandling.ts::29
232-
examples/snippets/batch/gettingStartedErrorHandling.ts:31:38
233-
examples/snippets/batch/gettingStartedErrorHandling.ts:40:43
231+
examples/snippets/batch/gettingStartedErrorHandling.ts::24
232+
examples/snippets/batch/gettingStartedErrorHandling.ts:26:30
233+
examples/snippets/batch/gettingStartedErrorHandling.ts:32:
234234
--8<--
235235
```
236236

237237
1. Any exception works here. See [extending BatchProcessorSync section, if you want to override this behavior.](#extending-batchprocessor)
238238

239-
2. Exceptions raised in `record_handler` will propagate to `process_partial_response`. <br/><br/> We catch them and include each failed batch item identifier in the response dictionary (see `Sample response` tab).
239+
2. Exceptions raised in `recordHandler` will propagate to `process_partial_response`. <br/><br/> We catch them and include each failed batch item identifier in the response dictionary (see `Sample response` tab).
240240

241241
=== "Sample response"
242242

@@ -397,7 +397,7 @@ Use the `BatchProcessor` directly in your function to access a list of all retur
397397
* **When successful**. We will include a tuple with `success`, the result of `recordHandler`, and the batch record
398398
* **When failed**. We will include a tuple with `fail`, exception as a string, and the batch record
399399

400-
```typescript hl_lines="25 27-28 30-33 38" title="Accessing processed messages"
400+
```typescript hl_lines="17 19-20 23 28" title="Accessing processed messages"
401401
--8<-- "examples/snippets/batch/accessProcessedMessages.ts"
402402
```
403403

@@ -410,7 +410,7 @@ Within your `recordHandler` function, you might need access to the Lambda contex
410410

411411
We can automatically inject the [Lambda context](https://docs.aws.amazon.com/lambda/latest/dg/typescript-context.html){target="_blank"} into your `recordHandler` as optional second argument if you register it when using `BatchProcessorSync` or the `processPartialResponseSync` function.
412412

413-
```typescript hl_lines="17 35"
413+
```typescript hl_lines="12 27"
414414
--8<-- "examples/snippets/batch/accessLambdaContext.ts"
415415
```
416416

@@ -425,7 +425,7 @@ For these scenarios, you can subclass `BatchProcessor` and quickly override `suc
425425

426426
Let's suppose you'd like to add a metric named `BatchRecordFailures` for each batch record that failed processing
427427

428-
```typescript hl_lines="3 20 24 31 37" title="Extending failure handling mechanism in BatchProcessor"
428+
```typescript hl_lines="3 15 19 26 32" title="Extending failure handling mechanism in BatchProcessor"
429429
--8<-- "examples/snippets/batch/extendingFailure.ts"
430430
```
431431

examples/app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"constructs": "^10.3.0",
4141
"jest": "^29.7.0",
4242
"source-map-support": "^0.5.21",
43-
"ts-jest": "^29.1.2",
44-
"tsx": "^4.10.5",
43+
"ts-jest": "^29.1.3",
44+
"tsx": "^4.11.0",
4545
"typescript": "^5.4.5"
4646
},
4747
"dependencies": {
@@ -61,7 +61,7 @@
6161
"constructs": "^10.3.0",
6262
"esbuild": "^0.21.3",
6363
"jest": "^29.7.0",
64-
"ts-jest": "^29.1.2",
64+
"ts-jest": "^29.1.3",
6565
"ts-node": "^10.9.2",
6666
"typescript": "^5.4.5"
6767
}

examples/snippets/batch/accessLambdaContext.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import {
44
processPartialResponse,
55
} from '@aws-lambda-powertools/batch';
66
import { Logger } from '@aws-lambda-powertools/logger';
7-
import type {
8-
SQSEvent,
9-
SQSRecord,
10-
Context,
11-
SQSBatchResponse,
12-
} from 'aws-lambda';
7+
import type { SQSRecord, Context, SQSHandler } from 'aws-lambda';
138

149
const processor = new BatchProcessor(EventType.SQS);
1510
const logger = new Logger();
@@ -27,11 +22,7 @@ const recordHandler = (record: SQSRecord, lambdaContext?: Context): void => {
2722
}
2823
};
2924

30-
export const handler = async (
31-
event: SQSEvent,
32-
context: Context
33-
): Promise<SQSBatchResponse> => {
34-
return processPartialResponse(event, recordHandler, processor, {
25+
export const handler: SQSHandler = async (event, context) =>
26+
processPartialResponse(event, recordHandler, processor, {
3527
context,
3628
});
37-
};

examples/snippets/batch/accessProcessedMessages.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { BatchProcessor, EventType } from '@aws-lambda-powertools/batch';
22
import { Logger } from '@aws-lambda-powertools/logger';
3-
import type {
4-
SQSEvent,
5-
SQSRecord,
6-
Context,
7-
SQSBatchResponse,
8-
} from 'aws-lambda';
3+
import type { SQSRecord, SQSHandler } from 'aws-lambda';
94

105
const processor = new BatchProcessor(EventType.SQS);
116
const logger = new Logger();
@@ -18,19 +13,14 @@ const recordHandler = (record: SQSRecord): void => {
1813
}
1914
};
2015

21-
export const handler = async (
22-
event: SQSEvent,
23-
context: Context
24-
): Promise<SQSBatchResponse> => {
16+
export const handler: SQSHandler = async (event, context) => {
2517
const batch = event.Records; // (1)!
2618

2719
processor.register(batch, recordHandler, { context }); // (2)!
2820
const processedMessages = await processor.process();
2921

3022
for (const message of processedMessages) {
31-
const status: 'success' | 'fail' = message[0];
32-
const error = message[1];
33-
const record = message[2];
23+
const [status, error, record] = message;
3424

3525
logger.info('Processed record', { status, record, error });
3626
}

examples/snippets/batch/advancedTracingRecordHandler.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import {
66
import { Tracer } from '@aws-lambda-powertools/tracer';
77
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
88
import middy from '@middy/core';
9-
import type {
10-
SQSEvent,
11-
SQSRecord,
12-
Context,
13-
SQSBatchResponse,
14-
} from 'aws-lambda';
9+
import type { SQSRecord, SQSHandler, SQSEvent } from 'aws-lambda';
1510

1611
const processor = new BatchProcessor(EventType.SQS);
1712
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
@@ -35,10 +30,8 @@ const recordHandler = async (record: SQSRecord): Promise<void> => {
3530
subsegment?.close(); // (3)!
3631
};
3732

38-
export const handler = middy(
39-
async (event: SQSEvent, context: Context): Promise<SQSBatchResponse> => {
40-
return processPartialResponse(event, recordHandler, processor, {
41-
context,
42-
});
43-
}
33+
export const handler: SQSHandler = middy(async (event: SQSEvent, context) =>
34+
processPartialResponse(event, recordHandler, processor, {
35+
context,
36+
})
4437
).use(captureLambdaHandler(tracer));

examples/snippets/batch/customPartialProcessor.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
FailureResponse,
1515
BaseRecord,
1616
} from '@aws-lambda-powertools/batch/types';
17-
import type { SQSEvent, Context, SQSBatchResponse } from 'aws-lambda';
17+
import type { SQSHandler } from 'aws-lambda';
1818

1919
const tableName = process.env.TABLE_NAME || 'table-not-found';
2020

@@ -89,11 +89,7 @@ const recordHandler = (): number => {
8989
return Math.floor(randomInt(1, 10));
9090
};
9191

92-
export const handler = async (
93-
event: SQSEvent,
94-
context: Context
95-
): Promise<SQSBatchResponse> => {
96-
return processPartialResponse(event, recordHandler, processor, {
92+
export const handler: SQSHandler = async (event, context) =>
93+
processPartialResponse(event, recordHandler, processor, {
9794
context,
9895
});
99-
};

examples/snippets/batch/extendingFailure.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ import type {
99
EventSourceDataClassTypes,
1010
} from '@aws-lambda-powertools/batch/types';
1111
import { Logger } from '@aws-lambda-powertools/logger';
12-
import type {
13-
SQSEvent,
14-
SQSRecord,
15-
Context,
16-
SQSBatchResponse,
17-
} from 'aws-lambda';
12+
import type { SQSRecord, SQSHandler } from 'aws-lambda';
1813

1914
class MyProcessor extends BatchProcessor {
2015
#metrics: Metrics;
@@ -45,11 +40,7 @@ const recordHandler = (record: SQSRecord): void => {
4540
}
4641
};
4742

48-
export const handler = async (
49-
event: SQSEvent,
50-
context: Context
51-
): Promise<SQSBatchResponse> => {
52-
return processPartialResponse(event, recordHandler, processor, {
43+
export const handler: SQSHandler = async (event, context) =>
44+
processPartialResponse(event, recordHandler, processor, {
5345
context,
5446
});
55-
};

examples/snippets/batch/gettingStartedDynamoDBStreams.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import {
44
processPartialResponse,
55
} from '@aws-lambda-powertools/batch';
66
import { Logger } from '@aws-lambda-powertools/logger';
7-
import type {
8-
DynamoDBStreamEvent,
9-
DynamoDBRecord,
10-
Context,
11-
DynamoDBBatchResponse,
12-
} from 'aws-lambda';
7+
import type { DynamoDBRecord, DynamoDBStreamHandler } from 'aws-lambda';
138

149
const processor = new BatchProcessor(EventType.DynamoDBStreams); // (1)!
1510
const logger = new Logger();
@@ -25,11 +20,7 @@ const recordHandler = async (record: DynamoDBRecord): Promise<void> => {
2520
}
2621
};
2722

28-
export const handler = async (
29-
event: DynamoDBStreamEvent,
30-
context: Context
31-
): Promise<DynamoDBBatchResponse> => {
32-
return processPartialResponse(event, recordHandler, processor, {
23+
export const handler: DynamoDBStreamHandler = async (event, context) =>
24+
processPartialResponse(event, recordHandler, processor, {
3325
context,
3426
});
35-
};

examples/snippets/batch/gettingStartedErrorHandling.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import {
44
processPartialResponse,
55
} from '@aws-lambda-powertools/batch';
66
import { Logger } from '@aws-lambda-powertools/logger';
7-
import type {
8-
SQSEvent,
9-
SQSRecord,
10-
Context,
11-
SQSBatchResponse,
12-
} from 'aws-lambda';
7+
import type { SQSRecord, SQSHandler } from 'aws-lambda';
138

149
const processor = new BatchProcessor(EventType.SQS);
1510
const logger = new Logger();
@@ -32,12 +27,8 @@ const recordHandler = async (record: SQSRecord): Promise<void> => {
3227
}
3328
};
3429

35-
export const handler = async (
36-
event: SQSEvent,
37-
context: Context
38-
): Promise<SQSBatchResponse> => {
30+
export const handler: SQSHandler = async (event, context) =>
3931
// prettier-ignore
40-
return processPartialResponse(event, recordHandler, processor, { // (2)!
32+
processPartialResponse(event, recordHandler, processor, { // (2)!
4133
context,
4234
});
43-
};

examples/snippets/batch/gettingStartedKinesis.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import {
44
processPartialResponse,
55
} from '@aws-lambda-powertools/batch';
66
import { Logger } from '@aws-lambda-powertools/logger';
7-
import type {
8-
KinesisStreamEvent,
9-
KinesisStreamRecord,
10-
Context,
11-
KinesisStreamBatchResponse,
12-
} from 'aws-lambda';
7+
import type { KinesisStreamHandler, KinesisStreamRecord } from 'aws-lambda';
138

149
const processor = new BatchProcessor(EventType.KinesisDataStreams); // (1)!
1510
const logger = new Logger();
@@ -20,11 +15,7 @@ const recordHandler = async (record: KinesisStreamRecord): Promise<void> => {
2015
logger.info('Processed item', { item: payload });
2116
};
2217

23-
export const handler = async (
24-
event: KinesisStreamEvent,
25-
context: Context
26-
): Promise<KinesisStreamBatchResponse> => {
27-
return processPartialResponse(event, recordHandler, processor, {
18+
export const handler: KinesisStreamHandler = async (event, context) =>
19+
processPartialResponse(event, recordHandler, processor, {
2820
context,
2921
});
30-
};

0 commit comments

Comments
 (0)