Skip to content

Commit f63cadc

Browse files
authored
Merge branch 'develop' into feat-async-btach-processor
2 parents 5596509 + 04ee1d0 commit f63cadc

File tree

69 files changed

+3265
-1193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3265
-1193
lines changed

.github/workflows/auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- name: Dependabot metadata
1616
id: metadata
17-
uses: dependabot/fetch-metadata@v1.3.5
17+
uses: dependabot/fetch-metadata@v1.3.6
1818
with:
1919
github-token: "${{ secrets.GITHUB_TOKEN }}"
2020
- name: Enable auto-merge for mypy-boto3 stubs Dependabot PRs

.github/workflows/publish_v2_layer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
# NOTE: we need QEMU to build Layer against a different architecture (e.g., ARM)
6666
- name: Set up Docker Buildx
6767
id: builder
68-
uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # v2.0.0
68+
uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2.4.0
6969
with:
7070
install: true
7171
driver: docker

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
update_release_draft:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: release-drafter/release-drafter@6df64e4ba4842c203c604c1f45246c5863410adb # v5.20.1
13+
- uses: release-drafter/release-drafter@cfc5540ebc9d65a8731f02032e3d44db5e449fb6 # v5.20.1
1414
env:
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/reusable_publish_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
poetry run mike set-default --push latest
6666
6767
- name: Release API docs
68-
uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935 # v3.9.0
68+
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 # v3.9.2
6969
env:
7070
VERSION: ${{ inputs.version }}
7171
with:
@@ -75,7 +75,7 @@ jobs:
7575
destination_dir: ${{ env.VERSION }}/api
7676
- name: Release API docs to latest
7777
if: ${{ inputs.alias == 'latest' }}
78-
uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935 # v3.9.0
78+
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 # v3.9.2
7979
with:
8080
github_token: ${{ secrets.GITHUB_TOKEN }}
8181
publish_dir: ./api

.github/workflows/run-e2e-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
id-token: write # needed to request JWT with GitHub's OIDC Token endpoint. docs: https://bit.ly/3MNgQO9
2727
contents: read
2828
strategy:
29+
fail-fast: false # needed so if a version fails, the others will still be able to complete and cleanup
2930
matrix:
3031
version: ["3.7", "3.8", "3.9"]
3132
if: ${{ github.actor != 'dependabot[bot]' }}

.github/workflows/secure_workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Checkout code
1717
uses: actions/checkout@v3
1818
- name: Ensure 3rd party workflows have SHA pinned
19-
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@af2eb3226618e2494e3d9084f515ad6dcf16e229 # v2.0.1
19+
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@bd2868d14a756969608c618665394415a238de69 # v2.0.5
2020
with:
2121
# Trusted GitHub Actions and/or organizations
2222
allowlist: |

CHANGELOG.md

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,134 @@
44
<a name="unreleased"></a>
55
# Unreleased
66

7+
## Bug Fixes
8+
9+
* parallel_run should fail when e2e tests fail
10+
* bump aws-cdk version
11+
* **ci:** scope e2e tests by python version
12+
13+
## Documentation
14+
15+
* **event-source:** fix incorrect method in example CloudWatch Logs ([#1857](https://github.com/awslabs/aws-lambda-powertools-python/issues/1857))
16+
17+
## Maintenance
18+
19+
* **deps:** bump dependabot/fetch-metadata from 1.3.5 to 1.3.6 ([#1855](https://github.com/awslabs/aws-lambda-powertools-python/issues/1855))
20+
* **deps-dev:** bump aws-cdk-lib from 2.62.0 to 2.62.1 ([#1866](https://github.com/awslabs/aws-lambda-powertools-python/issues/1866))
21+
* **deps-dev:** bump mypy-boto3-cloudformation from 1.26.35.post1 to 1.26.57 ([#1865](https://github.com/awslabs/aws-lambda-powertools-python/issues/1865))
22+
* **deps-dev:** bump coverage from 7.0.5 to 7.1.0 ([#1862](https://github.com/awslabs/aws-lambda-powertools-python/issues/1862))
23+
* **deps-dev:** bump aws-cdk-lib from 2.61.1 to 2.62.0 ([#1863](https://github.com/awslabs/aws-lambda-powertools-python/issues/1863))
24+
* **deps-dev:** bump mypy-boto3-lambda from 1.26.49 to 1.26.55 ([#1856](https://github.com/awslabs/aws-lambda-powertools-python/issues/1856))
25+
26+
27+
<a name="v2.7.0"></a>
28+
## [v2.7.0] - 2023-01-24
29+
## Bug Fixes
30+
31+
* git-chlg docker image is broken
32+
33+
## Features
34+
35+
* **feature_flags:** Add Time based feature flags actions ([#1846](https://github.com/awslabs/aws-lambda-powertools-python/issues/1846))
36+
37+
## Maintenance
38+
39+
* update v2 layer ARN on documentation
40+
* **deps:** bump peaceiris/actions-gh-pages from 3.9.1 to 3.9.2 ([#1841](https://github.com/awslabs/aws-lambda-powertools-python/issues/1841))
41+
* **deps:** bump future from 0.18.2 to 0.18.3 ([#1836](https://github.com/awslabs/aws-lambda-powertools-python/issues/1836))
42+
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 2.0.4 to 2.0.5 ([#1837](https://github.com/awslabs/aws-lambda-powertools-python/issues/1837))
43+
* **deps-dev:** bump mkdocs-material from 9.0.4 to 9.0.5 ([#1840](https://github.com/awslabs/aws-lambda-powertools-python/issues/1840))
44+
* **deps-dev:** bump types-requests from 2.28.11.7 to 2.28.11.8 ([#1843](https://github.com/awslabs/aws-lambda-powertools-python/issues/1843))
45+
* **deps-dev:** bump mypy-boto3-cloudwatch from 1.26.30 to 1.26.52 ([#1847](https://github.com/awslabs/aws-lambda-powertools-python/issues/1847))
46+
* **deps-dev:** bump pytest from 7.2.0 to 7.2.1 ([#1838](https://github.com/awslabs/aws-lambda-powertools-python/issues/1838))
47+
* **deps-dev:** bump aws-cdk-lib from 2.60.0 to 2.61.1 ([#1849](https://github.com/awslabs/aws-lambda-powertools-python/issues/1849))
48+
* **deps-dev:** bump mypy-boto3-logs from 1.26.49 to 1.26.53 ([#1850](https://github.com/awslabs/aws-lambda-powertools-python/issues/1850))
49+
* **deps-dev:** bump mkdocs-material from 9.0.5 to 9.0.6 ([#1851](https://github.com/awslabs/aws-lambda-powertools-python/issues/1851))
50+
* **deps-dev:** bump mkdocs-material from 9.0.3 to 9.0.4 ([#1833](https://github.com/awslabs/aws-lambda-powertools-python/issues/1833))
51+
* **deps-dev:** bump mypy-boto3-logs from 1.26.43 to 1.26.49 ([#1834](https://github.com/awslabs/aws-lambda-powertools-python/issues/1834))
52+
* **deps-dev:** bump mypy-boto3-secretsmanager from 1.26.40 to 1.26.49 ([#1835](https://github.com/awslabs/aws-lambda-powertools-python/issues/1835))
53+
* **deps-dev:** bump mypy-boto3-lambda from 1.26.18 to 1.26.49 ([#1832](https://github.com/awslabs/aws-lambda-powertools-python/issues/1832))
54+
* **deps-dev:** bump aws-cdk-lib from 2.59.0 to 2.60.0 ([#1831](https://github.com/awslabs/aws-lambda-powertools-python/issues/1831))
55+
56+
57+
<a name="v2.6.0"></a>
58+
## [v2.6.0] - 2023-01-12
59+
## Bug Fixes
60+
61+
* **api_gateway:** fixed custom metrics issue when using debug mode ([#1827](https://github.com/awslabs/aws-lambda-powertools-python/issues/1827))
62+
63+
## Documentation
64+
65+
* **logger:** fix incorrect field names in example structured logs ([#1830](https://github.com/awslabs/aws-lambda-powertools-python/issues/1830))
66+
* **logger:** Add warning of uncaught exceptions ([#1826](https://github.com/awslabs/aws-lambda-powertools-python/issues/1826))
67+
68+
## Maintenance
69+
70+
* update v2 layer ARN on documentation
71+
* **deps:** bump pydantic from 1.10.2 to 1.10.4 ([#1817](https://github.com/awslabs/aws-lambda-powertools-python/issues/1817))
72+
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 2.0.1 to 2.0.3 ([#1801](https://github.com/awslabs/aws-lambda-powertools-python/issues/1801))
73+
* **deps:** bump release-drafter/release-drafter from 5.21.1 to 5.22.0 ([#1802](https://github.com/awslabs/aws-lambda-powertools-python/issues/1802))
74+
* **deps:** bump gitpython from 3.1.29 to 3.1.30 ([#1812](https://github.com/awslabs/aws-lambda-powertools-python/issues/1812))
75+
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 2.0.3 to 2.0.4 ([#1821](https://github.com/awslabs/aws-lambda-powertools-python/issues/1821))
76+
* **deps:** bump peaceiris/actions-gh-pages from 3.9.0 to 3.9.1 ([#1814](https://github.com/awslabs/aws-lambda-powertools-python/issues/1814))
77+
* **deps-dev:** bump mkdocs-material from 8.5.11 to 9.0.2 ([#1808](https://github.com/awslabs/aws-lambda-powertools-python/issues/1808))
78+
* **deps-dev:** bump mypy-boto3-ssm from 1.26.11.post1 to 1.26.43 ([#1819](https://github.com/awslabs/aws-lambda-powertools-python/issues/1819))
79+
* **deps-dev:** bump mypy-boto3-logs from 1.26.27 to 1.26.43 ([#1820](https://github.com/awslabs/aws-lambda-powertools-python/issues/1820))
80+
* **deps-dev:** bump filelock from 3.8.2 to 3.9.0 ([#1816](https://github.com/awslabs/aws-lambda-powertools-python/issues/1816))
81+
* **deps-dev:** bump mypy-boto3-cloudformation from 1.26.11.post1 to 1.26.35.post1 ([#1818](https://github.com/awslabs/aws-lambda-powertools-python/issues/1818))
82+
* **deps-dev:** bump ijson from 3.1.4 to 3.2.0.post0 ([#1815](https://github.com/awslabs/aws-lambda-powertools-python/issues/1815))
83+
* **deps-dev:** bump coverage from 6.5.0 to 7.0.3 ([#1806](https://github.com/awslabs/aws-lambda-powertools-python/issues/1806))
84+
* **deps-dev:** bump flake8-builtins from 2.0.1 to 2.1.0 ([#1799](https://github.com/awslabs/aws-lambda-powertools-python/issues/1799))
85+
* **deps-dev:** bump coverage from 7.0.3 to 7.0.4 ([#1822](https://github.com/awslabs/aws-lambda-powertools-python/issues/1822))
86+
* **deps-dev:** bump mypy-boto3-secretsmanager from 1.26.12 to 1.26.40 ([#1811](https://github.com/awslabs/aws-lambda-powertools-python/issues/1811))
87+
* **deps-dev:** bump isort from 5.11.3 to 5.11.4 ([#1809](https://github.com/awslabs/aws-lambda-powertools-python/issues/1809))
88+
* **deps-dev:** bump aws-cdk-lib from 2.55.1 to 2.59.0 ([#1810](https://github.com/awslabs/aws-lambda-powertools-python/issues/1810))
89+
* **deps-dev:** bump importlib-metadata from 5.1.0 to 6.0.0 ([#1804](https://github.com/awslabs/aws-lambda-powertools-python/issues/1804))
90+
* **deps-dev:** bump mkdocs-material from 9.0.2 to 9.0.3 ([#1823](https://github.com/awslabs/aws-lambda-powertools-python/issues/1823))
91+
* **deps-dev:** bump black from 22.10.0 to 22.12.0 ([#1770](https://github.com/awslabs/aws-lambda-powertools-python/issues/1770))
92+
* **deps-dev:** bump flake8-black from 0.3.5 to 0.3.6 ([#1792](https://github.com/awslabs/aws-lambda-powertools-python/issues/1792))
93+
* **deps-dev:** bump coverage from 7.0.4 to 7.0.5 ([#1829](https://github.com/awslabs/aws-lambda-powertools-python/issues/1829))
94+
* **deps-dev:** bump types-requests from 2.28.11.5 to 2.28.11.7 ([#1795](https://github.com/awslabs/aws-lambda-powertools-python/issues/1795))
95+
96+
97+
<a name="v2.5.0"></a>
98+
## [v2.5.0] - 2022-12-21
99+
## Bug Fixes
100+
101+
* **event_handlers:** omit explicit None HTTP header values ([#1793](https://github.com/awslabs/aws-lambda-powertools-python/issues/1793))
102+
7103
## Documentation
8104

9105
* **idempotency:** fix, improve, and increase visibility for batch integration ([#1776](https://github.com/awslabs/aws-lambda-powertools-python/issues/1776))
10106
* **validation:** fix broken link; enrich built-in jmespath links ([#1777](https://github.com/awslabs/aws-lambda-powertools-python/issues/1777))
11107

108+
## Features
109+
110+
* **logger:** unwrap event from common models if asked to log ([#1778](https://github.com/awslabs/aws-lambda-powertools-python/issues/1778))
111+
12112
## Maintenance
13113

114+
* update v2 layer ARN on documentation
14115
* **common:** reusable function to extract event from models
15116
* **deps:** bump certifi from 2022.9.24 to 2022.12.7 ([#1768](https://github.com/awslabs/aws-lambda-powertools-python/issues/1768))
16117
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 1.4.0 to 2.0.1 ([#1752](https://github.com/awslabs/aws-lambda-powertools-python/issues/1752))
17118
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 1.3.0 to 1.4.0 ([#1749](https://github.com/awslabs/aws-lambda-powertools-python/issues/1749))
119+
* **deps-dev:** bump pytest-asyncio from 0.20.2 to 0.20.3 ([#1767](https://github.com/awslabs/aws-lambda-powertools-python/issues/1767))
120+
* **deps-dev:** bump mypy-boto3-cloudwatch from 1.26.0.post1 to 1.26.17 ([#1753](https://github.com/awslabs/aws-lambda-powertools-python/issues/1753))
121+
* **deps-dev:** bump isort from 5.10.1 to 5.11.2 ([#1782](https://github.com/awslabs/aws-lambda-powertools-python/issues/1782))
122+
* **deps-dev:** bump mypy-boto3-cloudwatch from 1.26.17 to 1.26.30 ([#1785](https://github.com/awslabs/aws-lambda-powertools-python/issues/1785))
123+
* **deps-dev:** bump mypy-boto3-dynamodb from 1.26.13.post16 to 1.26.24 ([#1765](https://github.com/awslabs/aws-lambda-powertools-python/issues/1765))
124+
* **deps-dev:** bump aws-cdk-lib from 2.54.0 to 2.55.1 ([#1787](https://github.com/awslabs/aws-lambda-powertools-python/issues/1787))
18125
* **deps-dev:** bump aws-cdk-lib from 2.53.0 to 2.54.0 ([#1764](https://github.com/awslabs/aws-lambda-powertools-python/issues/1764))
19126
* **deps-dev:** bump flake8-bugbear from 22.10.27 to 22.12.6 ([#1760](https://github.com/awslabs/aws-lambda-powertools-python/issues/1760))
20127
* **deps-dev:** bump filelock from 3.8.0 to 3.8.2 ([#1759](https://github.com/awslabs/aws-lambda-powertools-python/issues/1759))
21-
* **deps-dev:** bump mypy-boto3-logs from 1.26.17 to 1.26.27 ([#1775](https://github.com/awslabs/aws-lambda-powertools-python/issues/1775))
128+
* **deps-dev:** bump pytest-xdist from 3.0.2 to 3.1.0 ([#1758](https://github.com/awslabs/aws-lambda-powertools-python/issues/1758))
22129
* **deps-dev:** bump mkdocs-material from 8.5.10 to 8.5.11 ([#1756](https://github.com/awslabs/aws-lambda-powertools-python/issues/1756))
23130
* **deps-dev:** bump importlib-metadata from 4.13.0 to 5.1.0 ([#1750](https://github.com/awslabs/aws-lambda-powertools-python/issues/1750))
24-
* **deps-dev:** bump mypy-boto3-dynamodb from 1.26.13.post16 to 1.26.24 ([#1765](https://github.com/awslabs/aws-lambda-powertools-python/issues/1765))
131+
* **deps-dev:** bump isort from 5.11.2 to 5.11.3 ([#1788](https://github.com/awslabs/aws-lambda-powertools-python/issues/1788))
25132
* **deps-dev:** bump flake8-black from 0.3.3 to 0.3.5 ([#1738](https://github.com/awslabs/aws-lambda-powertools-python/issues/1738))
26-
* **deps-dev:** bump mypy-boto3-cloudwatch from 1.26.0.post1 to 1.26.17 ([#1753](https://github.com/awslabs/aws-lambda-powertools-python/issues/1753))
27-
* **deps-dev:** bump pytest-xdist from 3.0.2 to 3.1.0 ([#1758](https://github.com/awslabs/aws-lambda-powertools-python/issues/1758))
133+
* **deps-dev:** bump mypy-boto3-logs from 1.26.17 to 1.26.27 ([#1775](https://github.com/awslabs/aws-lambda-powertools-python/issues/1775))
134+
* **tests:** move shared_functions to unit tests
28135

29136

30137
<a name="v2.4.0"></a>
@@ -2694,7 +2801,10 @@
26942801
* Merge pull request [#5](https://github.com/awslabs/aws-lambda-powertools-python/issues/5) from jfuss/feat/python38
26952802

26962803

2697-
[Unreleased]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.4.0...HEAD
2804+
[Unreleased]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.7.0...HEAD
2805+
[v2.7.0]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.6.0...v2.7.0
2806+
[v2.6.0]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.5.0...v2.6.0
2807+
[v2.5.0]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.4.0...v2.5.0
26982808
[v2.4.0]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.3.1...v2.4.0
26992809
[v2.3.1]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.3.0...v2.3.1
27002810
[v2.3.0]: https://github.com/awslabs/aws-lambda-powertools-python/compare/v2.2.0...v2.3.0

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ changelog:
102102
git fetch --tags origin
103103
CURRENT_VERSION=$(shell git describe --abbrev=0 --tag) ;\
104104
echo "[+] Pre-generating CHANGELOG for tag: $$CURRENT_VERSION" ;\
105-
docker run -v "${PWD}":/workdir quay.io/git-chglog/git-chglog > CHANGELOG.md
105+
docker run -v "${PWD}":/workdir quay.io/git-chglog/git-chglog:0.15.1 > CHANGELOG.md
106106

107107
mypy:
108108
poetry run mypy --pretty aws_lambda_powertools examples

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def resolve(self, event, context) -> Dict[str, Any]:
531531
event = event.raw_event
532532

533533
if self._debug:
534-
print(self._json_dump(event), end="")
534+
print(self._json_dump(event))
535535

536536
# Populate router(s) dependencies without keeping a reference to each registered router
537537
BaseRouter.current_event = self._to_proxy_event(event)
@@ -728,21 +728,26 @@ def _call_exception_handler(self, exp: Exception, route: Route) -> Optional[Resp
728728

729729
return None
730730

731-
def _to_response(self, result: Union[Dict, Response]) -> Response:
731+
def _to_response(self, result: Union[Dict, Tuple, Response]) -> Response:
732732
"""Convert the route's result to a Response
733733
734-
2 main result types are supported:
734+
3 main result types are supported:
735735
736736
- Dict[str, Any]: Rest api response with just the Dict to json stringify and content-type is set to
737737
application/json
738+
- Tuple[dict, int]: Same dict handling as above but with the option of including a status code
738739
- Response: returned as is, and allows for more flexibility
739740
"""
741+
status_code = HTTPStatus.OK
740742
if isinstance(result, Response):
741743
return result
744+
elif isinstance(result, tuple) and len(result) == 2:
745+
# Unpack result dict and status code from tuple
746+
result, status_code = result
742747

743748
logger.debug("Simple response detected, serializing return before constructing final response")
744749
return Response(
745-
status_code=200,
750+
status_code=status_code,
746751
content_type=content_types.APPLICATION_JSON,
747752
body=self._json_dump(result),
748753
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from aws_lambda_powertools.event_handler.api_gateway import Router
2+
from aws_lambda_powertools.utilities.data_classes import (
3+
ALBEvent,
4+
APIGatewayProxyEvent,
5+
APIGatewayProxyEventV2,
6+
LambdaFunctionUrlEvent,
7+
)
8+
9+
10+
class APIGatewayRouter(Router):
11+
"""Specialized Router class that exposes current_event as an APIGatewayProxyEvent"""
12+
13+
current_event: APIGatewayProxyEvent
14+
15+
16+
class APIGatewayHttpRouter(Router):
17+
"""Specialized Router class that exposes current_event as an APIGatewayProxyEventV2"""
18+
19+
current_event: APIGatewayProxyEventV2
20+
21+
22+
class LambdaFunctionUrlRouter(Router):
23+
"""Specialized Router class that exposes current_event as a LambdaFunctionUrlEvent"""
24+
25+
current_event: LambdaFunctionUrlEvent
26+
27+
28+
class ALBRouter(Router):
29+
"""Specialized Router class that exposes current_event as an ALBEvent"""
30+
31+
current_event: ALBEvent

aws_lambda_powertools/shared/headers_serializer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
4141
# Duplicate headers are combined with commas and included in the headers field.
4242
combined_headers: Dict[str, str] = {}
4343
for key, values in headers.items():
44+
# omit headers with explicit null values
45+
if values is None:
46+
continue
47+
4448
if isinstance(values, str):
4549
combined_headers[key] = values
4650
else:
@@ -60,13 +64,15 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
6064
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers-response
6165
"""
6266
payload: Dict[str, List[str]] = defaultdict(list)
63-
6467
for key, values in headers.items():
68+
# omit headers with explicit null values
69+
if values is None:
70+
continue
71+
6572
if isinstance(values, str):
6673
payload[key].append(values)
6774
else:
68-
for value in values:
69-
payload[key].append(value)
75+
payload[key].extend(values)
7076

7177
if cookies:
7278
payload.setdefault("Set-Cookie", [])
@@ -98,6 +104,10 @@ def serialize(self, headers: Dict[str, Union[str, List[str]]], cookies: List[Coo
98104
payload["headers"]["Set-Cookie"] = str(cookies[-1])
99105

100106
for key, values in headers.items():
107+
# omit headers with explicit null values
108+
if values is None:
109+
continue
110+
101111
if isinstance(values, str):
102112
payload["headers"][key] = values
103113
else:

0 commit comments

Comments
 (0)