Skip to content

Commit 762193f

Browse files
committed
chore(docs): initial upgrade guide for v2
1 parent 72f2c4f commit 762193f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

docs/upgrade.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Upgrade guide
3+
description: asdfasdf
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
## Migrate to v2 from v1
9+
10+
The transition from Powertools for Python v1 to v2 is as painless as possible, as we strove for minimal breaking changes.
11+
The API for event handler's Response has minor changes, but we kept the breaking changes to a bare minimum. We've also added some new features to some components.
12+
13+
???+ important
14+
Powertools for Python v2 drops suport for Python 3.6, following the Python 3.6 End-Of-Life (EOL) reached on December 23, 2021.
15+
16+
### Initial Steps
17+
18+
Before starting, it is highly suggested to make a copy of your current working project or create a new branch with git.
19+
20+
1. **Upgrade** Python to at least v3.7
21+
22+
2. **Ensure** you have the latest `aws-lambda-powertools`
23+
24+
```bash
25+
pip install aws-lambda-powertools -U
26+
```
27+
28+
3. **Check** the following sections to see if any of your code is affected
29+
30+
## Event Handler Response (headers and cookies)
31+
32+
The `Response` class of the event handler utility was changed slightly:
33+
34+
1. The `headers` parameter now has a type signature of `Dict[str, List[str]]`
35+
2. A new `cookies` parameter was added (type `List[str]`)
36+
37+
```python hl_lines="6 12 13"
38+
@app.get("/todos")
39+
def get_todos():
40+
# Before
41+
return Response(
42+
# ...
43+
headers={"Content-Type": "text/plain"}
44+
)
45+
46+
# After
47+
return Response(
48+
# ...
49+
headers={"Content-Type": ["text/plain"]},
50+
cookies=["CookieName=CookieValue"]
51+
)
52+
```
53+
54+
In the same way, it can be more convenient to just append headers to the response object:
55+
56+
```python hl_lines="4 5"
57+
@app.get("/todos")
58+
def get_todos():
59+
response = Response(...)
60+
response.headers["Content-Type"].append("text/plain")
61+
response.cookies.append("CookieName=CookieValue")
62+
```

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ nav:
1010
- Tutorial: tutorial/index.md
1111
- Roadmap: roadmap.md
1212
- API reference: api/" target="_blank
13+
- Upgrade guide: upgrade.md
1314
- Core utilities:
1415
- core/tracer.md
1516
- core/logger.md

0 commit comments

Comments
 (0)