Skip to content

Commit ff12e15

Browse files
author
Tom McCarthy
committed
docs: standardize documentation of custom boto config or boto3 sessions
1 parent 89b1e5f commit ff12e15

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

Diff for: docs/utilities/batch.md

+53-3
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ Use `PartialSQSProcessor` context manager to access a list of all return values
143143
return result
144144
```
145145

146-
### Passing custom boto3 config
146+
### Customizing boto configuration
147147

148-
If you need to pass custom configuration such as region to the SDK, you can pass your own [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html) to
149-
the `sqs_batch_processor` decorator:
148+
The **`config`** and **`boto3_session`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html)
149+
or a custom [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) when using the `sqs_batch_processor`
150+
decorator or `PartialSQSProcessor` class.
151+
152+
> Custom config example
150153
151154
=== "Decorator"
152155

@@ -193,6 +196,53 @@ the `sqs_batch_processor` decorator:
193196
return result
194197
```
195198

199+
> Custom boto3 session example
200+
201+
=== "Decorator"
202+
203+
```python hl_lines="4 12"
204+
from aws_lambda_powertools.utilities.batch import sqs_batch_processor
205+
from botocore.config import Config
206+
207+
session = boto3.session.Session()
208+
209+
def record_handler(record):
210+
# This will be called for each individual message from a batch
211+
# It should raise an exception if the message was not processed successfully
212+
return_value = do_something_with(record["body"])
213+
return return_value
214+
215+
@sqs_batch_processor(record_handler=record_handler, boto3_session=session)
216+
def lambda_handler(event, context):
217+
return {"statusCode": 200}
218+
```
219+
220+
=== "Context manager"
221+
222+
```python hl_lines="4 16"
223+
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor
224+
import boto3
225+
226+
session = boto3.session.Session()
227+
228+
def record_handler(record):
229+
# This will be called for each individual message from a batch
230+
# It should raise an exception if the message was not processed successfully
231+
return_value = do_something_with(record["body"])
232+
return return_value
233+
234+
235+
def lambda_handler(event, context):
236+
records = event["Records"]
237+
238+
processor = PartialSQSProcessor(boto3_session=session)
239+
240+
with processor(records, record_handler):
241+
result = processor.process()
242+
243+
return result
244+
```
245+
196246
### Suppressing exceptions
197247

198248
If you want to disable the default behavior where `SQSBatchProcessingError` is raised if there are any errors, you can pass the `suppress_exception` boolean argument.

Diff for: docs/utilities/idempotency.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ This means that we will raise **`IdempotencyKeyError`** if the evaluation of **`
548548

549549
### Customizing boto configuration
550550

551-
You can provide a custom boto configuration via **`boto_config`**, or an existing boto session via **`boto3_session`** parameters, when constructing the persistence store.
551+
The **`boto_config`** and **`boto3_session`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html) or a custom [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) when constructing the persistence store.
552552

553553
=== "Custom session"
554554

Diff for: docs/utilities/parameters.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Here is the mapping between this utility's functions and methods and the underly
505505

506506
### Customizing boto configuration
507507

508-
You can provide a custom boto configuration via **`config`**, or use a custom boto session via **`boto3_session`** parameters, when constructing any of the built-in provider classes.
508+
The **`config`** and **`boto3_session`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html) or a custom [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) when constructing any of the built-in provider classes.
509509

510510
> **Example**
511511

0 commit comments

Comments
 (0)