Skip to content

Commit ff96266

Browse files
committed
chore(docs): updated docs
1 parent 16f91f3 commit ff96266

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ You can use the `Response` class to have full control over the response. For exa
323323

324324
=== "fine_grained_responses.py"
325325

326-
```python hl_lines="7 24-29"
326+
```python hl_lines="7 25-30"
327327
--8<-- "examples/event_handler_rest/src/fine_grained_responses.py"
328328
```
329329

docs/upgrade.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ def get_todos():
5252
return Response(
5353
# ...
5454
headers={"Content-Type": ["text/plain"]},
55-
cookies=["CookieName=CookieValue"]
55+
cookies=[Cookie(name="session_id", value="12345", secure=True, http_only=True)],
5656
)
5757
```

examples/event_handler_rest/src/fine_grained_responses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aws_lambda_powertools import Logger, Tracer
77
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response, content_types
88
from aws_lambda_powertools.logging import correlation_paths
9+
from aws_lambda_powertools.shared.cookies import Cookie
910
from aws_lambda_powertools.utilities.typing import LambdaContext
1011

1112
tracer = Tracer()
@@ -26,7 +27,7 @@ def get_todos():
2627
content_type=content_types.APPLICATION_JSON,
2728
body=todos.json()[:10],
2829
headers=custom_headers,
29-
cookies=["<cookie-name>=<cookie-value>; Secure; Expires=<date>"],
30+
cookies=[Cookie(name="session_id", value="12345", secure=True)],
3031
)
3132

3233

examples/event_handler_rest/src/fine_grained_responses_output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"multiValueHeaders": {
44
"Content-Type": ["application/json"],
55
"X-Transaction-Id": ["3490eea9-791b-47a0-91a4-326317db61a9"],
6-
"Set-Cookie": ["<cookie-name>=<cookie-value>; Secure; Expires=<date>"]
6+
"Set-Cookie": ["session_id=12345; Secure"]
77
},
88
"body": "{\"todos\":[{\"userId\":1,\"id\":1,\"title\":\"delectus aut autem\",\"completed\":false},{\"userId\":1,\"id\":2,\"title\":\"quis ut nam facilis et officia qui\",\"completed\":false},{\"userId\":1,\"id\":3,\"title\":\"fugiat veniam minus\",\"completed\":false},{\"userId\":1,\"id\":4,\"title\":\"et porro tempora\",\"completed\":true},{\"userId\":1,\"id\":5,\"title\":\"laboriosam mollitia et enim quasi adipisci quia provident illum\",\"completed\":false},{\"userId\":1,\"id\":6,\"title\":\"qui ullam ratione quibusdam voluptatem quia omnis\",\"completed\":false},{\"userId\":1,\"id\":7,\"title\":\"illo expedita consequatur quia in\",\"completed\":false},{\"userId\":1,\"id\":8,\"title\":\"quo adipisci enim quam ut ab\",\"completed\":true},{\"userId\":1,\"id\":9,\"title\":\"molestiae perspiciatis ipsa\",\"completed\":false},{\"userId\":1,\"id\":10,\"title\":\"illo est ratione doloremque quia maiores aut\",\"completed\":true}]}",
99
"isBase64Encoded": false

tests/functional/event_handler/test_api_gateway.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
UnauthorizedError,
3131
)
3232
from aws_lambda_powertools.shared import constants
33+
from aws_lambda_powertools.shared.cookies import Cookie
3334
from aws_lambda_powertools.shared.json_encoder import Encoder
3435
from aws_lambda_powertools.utilities.data_classes import (
3536
ALBEvent,
@@ -98,7 +99,7 @@ def get_lambda() -> Response:
9899
def test_api_gateway_v1_cookies():
99100
# GIVEN a Http API V1 proxy type event
100101
app = APIGatewayRestResolver()
101-
cookie = "CookieMonster"
102+
cookie = Cookie(name="CookieMonster", value="MonsterCookie")
102103

103104
@app.get("/my/path")
104105
def get_lambda() -> Response:
@@ -111,7 +112,7 @@ def get_lambda() -> Response:
111112
# THEN process event correctly
112113
# AND set the current_event type as APIGatewayProxyEvent
113114
assert result["statusCode"] == 200
114-
assert result["multiValueHeaders"]["Set-Cookie"] == [cookie]
115+
assert result["multiValueHeaders"]["Set-Cookie"] == ["CookieMonster=MonsterCookie; Secure"]
115116

116117

117118
def test_api_gateway():
@@ -158,7 +159,7 @@ def my_path() -> Response:
158159
def test_api_gateway_v2_cookies():
159160
# GIVEN a Http API V2 proxy type event
160161
app = APIGatewayHttpResolver()
161-
cookie = "CookieMonster"
162+
cookie = Cookie(name="CookieMonster", value="MonsterCookie")
162163

163164
@app.post("/my/path")
164165
def my_path() -> Response:
@@ -172,7 +173,7 @@ def my_path() -> Response:
172173
# AND set the current_event type as APIGatewayProxyEventV2
173174
assert result["statusCode"] == 200
174175
assert result["headers"]["Content-Type"] == content_types.TEXT_PLAIN
175-
assert result["cookies"] == [cookie]
176+
assert result["cookies"] == ["CookieMonster=MonsterCookie; Secure"]
176177

177178

178179
def test_include_rule_matching():

tests/functional/event_handler/test_lambda_function_url.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from aws_lambda_powertools.event_handler import LambdaFunctionUrlResolver, Response, content_types
2+
from aws_lambda_powertools.shared.cookies import Cookie
23
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
34
from tests.functional.utils import load_event
45

@@ -28,7 +29,7 @@ def foo():
2829
def test_lambda_function_url_event_with_cookies():
2930
# GIVEN a Lambda Function Url type event
3031
app = LambdaFunctionUrlResolver()
31-
cookie = "CookieMonster"
32+
cookie = Cookie(name="CookieMonster", value="MonsterCookie")
3233

3334
@app.get("/")
3435
def foo():
@@ -42,7 +43,7 @@ def foo():
4243
# THEN process event correctly
4344
# AND set the current_event type as LambdaFunctionUrlEvent
4445
assert result["statusCode"] == 200
45-
assert result["cookies"] == [cookie]
46+
assert result["cookies"] == ["CookieMonster=MonsterCookie; Secure"]
4647

4748

4849
def test_lambda_function_url_no_matches():

0 commit comments

Comments
 (0)