Skip to content
Prev Previous commit
Next Next commit
chore(docs): updated docs
  • Loading branch information
rubenfonseca committed Sep 2, 2022
commit fe4ea7d8aa9ea5a09969730dae87e2dbd3b1f1c7
2 changes: 1 addition & 1 deletion docs/core/event_handler/api_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ You can use the `Response` class to have full control over the response. For exa

=== "fine_grained_responses.py"

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

Expand Down
2 changes: 1 addition & 1 deletion docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_todos():
return Response(
# ...
headers={"Content-Type": ["text/plain"]},
cookies=["CookieName=CookieValue"]
cookies=[Cookie(name="session_id", value="12345", secure=True, http_only=True)],
)
```

Expand Down
3 changes: 2 additions & 1 deletion examples/event_handler_rest/src/fine_grained_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response, content_types
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.utilities.typing import LambdaContext

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"multiValueHeaders": {
"Content-Type": ["application/json"],
"X-Transaction-Id": ["3490eea9-791b-47a0-91a4-326317db61a9"],
"Set-Cookie": ["<cookie-name>=<cookie-value>; Secure; Expires=<date>"]
"Set-Cookie": ["session_id=12345; Secure"]
},
"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}]}",
"isBase64Encoded": false
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/event_handler/test_api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
UnauthorizedError,
)
from aws_lambda_powertools.shared import constants
from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.shared.json_encoder import Encoder
from aws_lambda_powertools.utilities.data_classes import (
ALBEvent,
Expand Down Expand Up @@ -98,7 +99,7 @@ def get_lambda() -> Response:
def test_api_gateway_v1_cookies():
# GIVEN a Http API V1 proxy type event
app = APIGatewayRestResolver()
cookie = "CookieMonster"
cookie = Cookie(name="CookieMonster", value="MonsterCookie")

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


def test_api_gateway():
Expand Down Expand Up @@ -158,7 +159,7 @@ def my_path() -> Response:
def test_api_gateway_v2_cookies():
# GIVEN a Http API V2 proxy type event
app = APIGatewayHttpResolver()
cookie = "CookieMonster"
cookie = Cookie(name="CookieMonster", value="MonsterCookie")

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


def test_include_rule_matching():
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/event_handler/test_lambda_function_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from aws_lambda_powertools.event_handler import LambdaFunctionUrlResolver, Response, content_types
from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
from tests.functional.utils import load_event

Expand Down Expand Up @@ -28,7 +29,7 @@ def foo():
def test_lambda_function_url_event_with_cookies():
# GIVEN a Lambda Function Url type event
app = LambdaFunctionUrlResolver()
cookie = "CookieMonster"
cookie = Cookie(name="CookieMonster", value="MonsterCookie")

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


def test_lambda_function_url_no_matches():
Expand Down