From 43f32a197b291f2d1f451ef813b8497e87abaa55 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Fri, 5 Apr 2024 13:05:42 +0200 Subject: [PATCH] chore(docs): update batch docs highlight & links --- docs/snippets/batch/gettingStartedAsync.ts | 31 ---------------------- docs/utilities/batch.md | 13 +++++---- packages/batch/README.md | 9 +++---- 3 files changed, 9 insertions(+), 44 deletions(-) delete mode 100644 docs/snippets/batch/gettingStartedAsync.ts diff --git a/docs/snippets/batch/gettingStartedAsync.ts b/docs/snippets/batch/gettingStartedAsync.ts deleted file mode 100644 index 1d41e06624..0000000000 --- a/docs/snippets/batch/gettingStartedAsync.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - BatchProcessor, - EventType, - processPartialResponse, -} from '@aws-lambda-powertools/batch'; -import axios from 'axios'; // axios is an external dependency -import type { - SQSEvent, - SQSRecord, - Context, - SQSBatchResponse, -} from 'aws-lambda'; - -const processor = new BatchProcessor(EventType.SQS); - -const recordHandler = async (record: SQSRecord): Promise => { - const res = await axios.post('https://httpbin.org/anything', { - message: record.body, - }); - - return res.status; -}; - -export const handler = async ( - event: SQSEvent, - context: Context -): Promise => { - return await processPartialResponse(event, recordHandler, processor, { - context, - }); -}; diff --git a/docs/utilities/batch.md b/docs/utilities/batch.md index 486d7c12a0..0e3ef1ad3b 100644 --- a/docs/utilities/batch.md +++ b/docs/utilities/batch.md @@ -423,12 +423,11 @@ For these scenarios, you can subclass `BatchProcessor` and quickly override `suc * **`successHandler()`** – Keeps track of successful batch records * **`failureHandler()`** – Keeps track of failed batch records -???+ example - Let's suppose you'd like to add a metric named `BatchRecordFailures` for each batch record that failed processing - - ```typescript hl_lines="17 21 25 31 35" title="Extending failure handling mechanism in BatchProcessor" - --8<-- "docs/snippets/batch/extendingFailure.ts" - ``` +Let's suppose you'd like to add a metric named `BatchRecordFailures` for each batch record that failed processing + +```typescript hl_lines="3 20 24 31 37" title="Extending failure handling mechanism in BatchProcessor" +--8<-- "docs/snippets/batch/extendingFailure.ts" +``` ### Create your own partial processor @@ -463,7 +462,7 @@ classDiagram You can then use this class as a context manager, or pass it to `processPartialResponseSync` to process the records in your Lambda handler function. -```typescript hl_lines="21 30 41 62 73 84" title="Creating a custom batch processor" +```typescript hl_lines="21 35 56 61 73 86" title="Creating a custom batch processor" --8<-- "docs/snippets/batch/customPartialProcessor.ts" ``` diff --git a/packages/batch/README.md b/packages/batch/README.md index 6807c77bde..e151314d71 100644 --- a/packages/batch/README.md +++ b/packages/batch/README.md @@ -177,7 +177,6 @@ import { EventType, processPartialResponse, } from '@aws-lambda-powertools/batch'; -import axios from 'axios'; // axios is an external dependency import type { SQSEvent, SQSRecord, @@ -188,8 +187,8 @@ import type { const processor = new BatchProcessor(EventType.SQS); const recordHandler = async (record: SQSRecord): Promise => { - const res = await axios.post('https://httpbin.org/anything', { - message: record.body, + const res = await fetch('https://httpbin.org/anything', { + body: JSON.stringify({ message: record.body }), }); return res.status; @@ -207,8 +206,6 @@ export const handler = async ( Check the [docs](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/batch/) for more examples. - - ## Contribute If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md). @@ -249,7 +246,7 @@ Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog po ### Using Lambda Layer -This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](#lambda-layers), you can add Powertools as a dev dependency (or as part of your virtual env) to not impact the development process. +This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency (or as part of your virtual env) to not impact the development process. ## Credits