Skip to content

Commit b8abfc4

Browse files
committed
chore(docs): update migration guide
1 parent f70ac4c commit b8abfc4

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

docs/upgrade.md

+87
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The transition from Powertools for Python v1 to v2 is as painless as possible, a
1111
Changes at a glance:
1212

1313
* The API for **event handler's `Response`** has minor changes to support multi value headers and cookies.
14+
* The **legacy SQS batch processor** was removed.
1415

1516
???+ important
1617
Powertools for Python v2 drops suport for Python 3.6, following the Python 3.6 End-Of-Life (EOL) reached on December 23, 2021.
@@ -55,3 +56,89 @@ def get_todos():
5556
cookies=["CookieName=CookieValue"]
5657
)
5758
```
59+
60+
## Legacy SQS Batch Processor
61+
62+
The deprecated `PartialSQSProcessor` and `sqs_batch_processor` were removed.
63+
You can migrate to the [native batch processing](https://aws.amazon.com/about-aws/whats-new/2021/11/aws-lambda-partial-batch-response-sqs-event-source/) capability by:
64+
65+
1. If you use **`sqs_batch_decorator`** you can now use **`batch_processor`** decorator
66+
2. If you use **`PartialSQSProcessor`** you can now use **`BatchProcessor`**
67+
3. [Enable the functionality](../utilities/batch#required-resources) on SQS
68+
4. Change your Lambda Handler to return the new response format
69+
70+
=== "Decorator: Before"
71+
72+
```python hl_lines="1 6"
73+
from aws_lambda_powertools.utilities.batch import sqs_batch_processor
74+
75+
def record_handler(record):
76+
return do_something_with(record["body"])
77+
78+
@sqs_batch_processor(record_handler=record_handler)
79+
def lambda_handler(event, context):
80+
return {"statusCode": 200}
81+
```
82+
83+
=== "Decorator: After"
84+
85+
```python hl_lines="3 5 11"
86+
import json
87+
88+
from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor
89+
90+
processor = BatchProcessor(event_type=EventType.SQS)
91+
92+
93+
def record_handler(record):
94+
return do_something_with(record["body"])
95+
96+
@batch_processor(record_handler=record_handler, processor=processor)
97+
def lambda_handler(event, context):
98+
return processor.response()
99+
```
100+
101+
=== "Context manager: Before"
102+
103+
```python hl_lines="1-2 4 14 19"
104+
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor
105+
from botocore.config import Config
106+
107+
config = Config(region_name="us-east-1")
108+
109+
def record_handler(record):
110+
return_value = do_something_with(record["body"])
111+
return return_value
112+
113+
114+
def lambda_handler(event, context):
115+
records = event["Records"]
116+
117+
processor = PartialSQSProcessor(config=config)
118+
119+
with processor(records, record_handler):
120+
result = processor.process()
121+
122+
return result
123+
```
124+
125+
=== "Context manager: After"
126+
127+
```python hl_lines="1 11"
128+
from aws_lambda_powertools.utilities.batch import BatchProcessor, EventType, batch_processor
129+
130+
131+
def record_handler(record):
132+
return_value = do_something_with(record["body"])
133+
return return_value
134+
135+
def lambda_handler(event, context):
136+
records = event["Records"]
137+
138+
processor = BatchProcessor(event_type=EventType.SQS)
139+
140+
with processor(records, record_handler):
141+
result = processor.process()
142+
143+
return processor.response()
144+
```

0 commit comments

Comments
 (0)