Skip to content

Commit 2ef3aec

Browse files
authored
Merge branch 'develop' into nested_event_sources
2 parents 0fa8f4f + a944307 commit 2ef3aec

Some content is hidden

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

44 files changed

+1453
-1107
lines changed

.github/workflows/quality_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- name: Complexity baseline
7474
run: make complexity-baseline
7575
- name: Upload coverage to Codecov
76-
uses: codecov/codecov-action@6d798873df2b1b8e5846dba6fb86631229fbcb17 # 4.4.0
76+
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # 4.4.1
7777
with:
7878
file: ./coverage.xml
7979
env_vars: PYTHON

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ repos:
3434
entry: poetry run cfn-lint
3535
language: system
3636
types: [yaml]
37+
exclude: examples/homepage/install/.*?/serverless\.yml$
3738
files: examples/.*
3839
- repo: https://github.com/rhysd/actionlint
3940
rev: "fd7ba3c382e13dcc0248e425b4cbc3f1185fa3ee" # v1.6.24

CHANGELOG.md

+46-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,57 @@
44
<a name="unreleased"></a>
55
# Unreleased
66

7+
## Bug Fixes
8+
9+
* **event_handler:** CORS Origin for ALBResolver multi-headers ([#4385](https://github.com/aws-powertools/powertools-lambda-python/issues/4385))
10+
11+
## Documentation
12+
13+
* **homepage:** Change installation to CDK v2 ([#4351](https://github.com/aws-powertools/powertools-lambda-python/issues/4351))
14+
15+
## Features
16+
17+
* **event_source:** add CloudFormationCustomResourceEvent data class. ([#4342](https://github.com/aws-powertools/powertools-lambda-python/issues/4342))
18+
719
## Maintenance
820

21+
* **deps:** bump aws-xray-sdk from 2.13.0 to 2.13.1 ([#4379](https://github.com/aws-powertools/powertools-lambda-python/issues/4379))
22+
* **deps:** bump codecov/codecov-action from 4.4.0 to 4.4.1 ([#4376](https://github.com/aws-powertools/powertools-lambda-python/issues/4376))
23+
* **deps:** bump squidfunk/mkdocs-material from `5358893` to `8a87f05` in /docs ([#4408](https://github.com/aws-powertools/powertools-lambda-python/issues/4408))
24+
* **deps:** bump typing-extensions from 4.11.0 to 4.12.0 ([#4404](https://github.com/aws-powertools/powertools-lambda-python/issues/4404))
25+
* **deps:** bump requests from 2.31.0 to 2.32.0 ([#4383](https://github.com/aws-powertools/powertools-lambda-python/issues/4383))
26+
* **deps:** bump squidfunk/mkdocs-material from `48d1914` to `5358893` in /docs ([#4377](https://github.com/aws-powertools/powertools-lambda-python/issues/4377))
27+
* **deps:** bump aws-encryption-sdk from 3.2.0 to 3.3.0 ([#4393](https://github.com/aws-powertools/powertools-lambda-python/issues/4393))
928
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates ([#4369](https://github.com/aws-powertools/powertools-lambda-python/issues/4369))
10-
* **deps-dev:** bump aws-cdk from 2.142.0 to 2.142.1 ([#4366](https://github.com/aws-powertools/powertools-lambda-python/issues/4366))
29+
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates ([#4396](https://github.com/aws-powertools/powertools-lambda-python/issues/4396))
30+
* **deps-dev:** bump ruff from 0.4.5 to 0.4.6 ([#4417](https://github.com/aws-powertools/powertools-lambda-python/issues/4417))
31+
* **deps-dev:** bump sentry-sdk from 2.2.1 to 2.3.1 ([#4398](https://github.com/aws-powertools/powertools-lambda-python/issues/4398))
32+
* **deps-dev:** bump ruff from 0.4.4 to 0.4.5 ([#4399](https://github.com/aws-powertools/powertools-lambda-python/issues/4399))
33+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.155 to 0.1.157 ([#4394](https://github.com/aws-powertools/powertools-lambda-python/issues/4394))
34+
* **deps-dev:** bump aws-cdk from 2.142.1 to 2.143.0 ([#4402](https://github.com/aws-powertools/powertools-lambda-python/issues/4402))
35+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.157 to 0.1.158 ([#4397](https://github.com/aws-powertools/powertools-lambda-python/issues/4397))
36+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.154 to 0.1.155 ([#4386](https://github.com/aws-powertools/powertools-lambda-python/issues/4386))
37+
* **deps-dev:** bump aws-cdk-lib from 2.142.1 to 2.143.0 ([#4403](https://github.com/aws-powertools/powertools-lambda-python/issues/4403))
38+
* **deps-dev:** bump pytest-asyncio from 0.23.6 to 0.23.7 ([#4387](https://github.com/aws-powertools/powertools-lambda-python/issues/4387))
39+
* **deps-dev:** bump sentry-sdk from 2.2.0 to 2.2.1 ([#4388](https://github.com/aws-powertools/powertools-lambda-python/issues/4388))
40+
* **deps-dev:** bump mypy-boto3-cloudformation from 1.34.84 to 1.34.111 in the boto-typing group ([#4392](https://github.com/aws-powertools/powertools-lambda-python/issues/4392))
41+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.152 to 0.1.154 ([#4382](https://github.com/aws-powertools/powertools-lambda-python/issues/4382))
42+
* **deps-dev:** bump coverage from 7.5.1 to 7.5.2 ([#4413](https://github.com/aws-powertools/powertools-lambda-python/issues/4413))
43+
* **deps-dev:** bump mypy-boto3-secretsmanager from 1.34.107 to 1.34.109 in the boto-typing group ([#4378](https://github.com/aws-powertools/powertools-lambda-python/issues/4378))
44+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.158 to 0.1.159 ([#4412](https://github.com/aws-powertools/powertools-lambda-python/issues/4412))
45+
* **deps-dev:** bump mypy-boto3-dynamodb from 1.34.97 to 1.34.113 in the boto-typing group ([#4409](https://github.com/aws-powertools/powertools-lambda-python/issues/4409))
46+
* **deps-dev:** bump mkdocs-material from 9.5.23 to 9.5.24 ([#4380](https://github.com/aws-powertools/powertools-lambda-python/issues/4380))
47+
* **deps-dev:** bump pytest from 8.2.0 to 8.2.1 ([#4381](https://github.com/aws-powertools/powertools-lambda-python/issues/4381))
48+
* **deps-dev:** bump aws-cdk-aws-lambda-python-alpha from 2.142.1a0 to 2.143.0a0 ([#4410](https://github.com/aws-powertools/powertools-lambda-python/issues/4410))
49+
* **deps-dev:** bump mkdocs-material from 9.5.24 to 9.5.25 ([#4411](https://github.com/aws-powertools/powertools-lambda-python/issues/4411))
50+
* **deps-dev:** bump aws-cdk-aws-lambda-python-alpha from 2.141.0a0 to 2.142.1a0 ([#4367](https://github.com/aws-powertools/powertools-lambda-python/issues/4367))
51+
* **deps-dev:** bump mypy-boto3-dynamodb from 1.34.113 to 1.34.114 in the boto-typing group ([#4416](https://github.com/aws-powertools/powertools-lambda-python/issues/4416))
52+
* **deps-dev:** bump coverage from 7.5.2 to 7.5.3 ([#4418](https://github.com/aws-powertools/powertools-lambda-python/issues/4418))
1153
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.150 to 0.1.152 ([#4368](https://github.com/aws-powertools/powertools-lambda-python/issues/4368))
54+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.159 to 0.1.161 ([#4420](https://github.com/aws-powertools/powertools-lambda-python/issues/4420))
1255
* **deps-dev:** bump cfn-lint from 0.87.2 to 0.87.3 ([#4370](https://github.com/aws-powertools/powertools-lambda-python/issues/4370))
56+
* **deps-dev:** bump cfn-lint from 0.87.3 to 0.87.4 ([#4419](https://github.com/aws-powertools/powertools-lambda-python/issues/4419))
57+
* **deps-dev:** bump aws-cdk from 2.142.0 to 2.142.1 ([#4366](https://github.com/aws-powertools/powertools-lambda-python/issues/4366))
1358

1459

1560
<a name="v2.38.1"></a>

aws_lambda_powertools/event_handler/api_gateway.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
validation_error_definition,
4444
validation_error_response_definition,
4545
)
46-
from aws_lambda_powertools.event_handler.util import _FrozenDict
46+
from aws_lambda_powertools.event_handler.util import _FrozenDict, extract_origin_header
4747
from aws_lambda_powertools.shared.cookies import Cookie
4848
from aws_lambda_powertools.shared.functions import powertools_dev_is_set
4949
from aws_lambda_powertools.shared.json_encoder import Encoder
@@ -782,7 +782,8 @@ def __init__(
782782

783783
def _add_cors(self, event: ResponseEventT, cors: CORSConfig):
784784
"""Update headers to include the configured Access-Control headers"""
785-
self.response.headers.update(cors.to_dict(event.get_header_value("Origin")))
785+
extracted_origin_header = extract_origin_header(event.resolved_headers_field)
786+
self.response.headers.update(cors.to_dict(extracted_origin_header))
786787

787788
def _add_cache_control(self, cache_control: str):
788789
"""Set the specified cache control headers for 200 http responses. For non-200 `no-cache` is used."""
@@ -2129,7 +2130,8 @@ def _not_found(self, method: str) -> ResponseBuilder:
21292130
headers = {}
21302131
if self._cors:
21312132
logger.debug("CORS is enabled, updating headers.")
2132-
headers.update(self._cors.to_dict(self.current_event.get_header_value("Origin")))
2133+
extracted_origin_header = extract_origin_header(self.current_event.resolved_headers_field)
2134+
headers.update(self._cors.to_dict(extracted_origin_header))
21332135

21342136
if method == "OPTIONS":
21352137
logger.debug("Pre-flight request detected. Returning CORS with null response")

aws_lambda_powertools/event_handler/util.py

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from typing import Any, Dict
2+
3+
from aws_lambda_powertools.utilities.data_classes.shared_functions import get_header_value
4+
5+
16
class _FrozenDict(dict):
27
"""
38
A dictionary that can be used as a key in another dictionary.
@@ -11,3 +16,27 @@ class _FrozenDict(dict):
1116

1217
def __hash__(self):
1318
return hash(frozenset(self.keys()))
19+
20+
21+
def extract_origin_header(resolver_headers: Dict[str, Any]):
22+
"""
23+
Extracts the 'origin' or 'Origin' header from the provided resolver headers.
24+
25+
The 'origin' or 'Origin' header can be either a single header or a multi-header.
26+
27+
Args:
28+
resolver_headers (Dict): A dictionary containing the headers.
29+
30+
Returns:
31+
Optional[str]: The value(s) of the origin header or None.
32+
"""
33+
resolved_header = get_header_value(
34+
headers=resolver_headers,
35+
name="origin",
36+
default_value=None,
37+
case_sensitive=False,
38+
)
39+
if isinstance(resolved_header, list):
40+
return resolved_header[0]
41+
42+
return resolved_header

aws_lambda_powertools/utilities/data_classes/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from .cloud_watch_custom_widget_event import CloudWatchDashboardCustomWidgetEvent
1919
from .cloud_watch_logs_event import CloudWatchLogsEvent
20+
from .cloudformation_custom_resource_event import CloudFormationCustomResourceEvent
2021
from .code_pipeline_job_event import CodePipelineJobEvent
2122
from .connect_contact_flow_event import ConnectContactFlowEvent
2223
from .dynamo_db_stream_event import DynamoDBStreamEvent
@@ -81,4 +82,5 @@
8182
"AWSConfigRuleEvent",
8283
"VPCLatticeEvent",
8384
"VPCLatticeEventV2",
85+
"CloudFormationCustomResourceEvent",
8486
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from typing import Any, Dict, Literal
2+
3+
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
4+
5+
6+
class CloudFormationCustomResourceEvent(DictWrapper):
7+
@property
8+
def request_type(self) -> Literal["Create", "Update", "Delete"]:
9+
return self["RequestType"]
10+
11+
@property
12+
def service_token(self) -> str:
13+
return self["ServiceToken"]
14+
15+
@property
16+
def response_url(self) -> str:
17+
return self["ResponseURL"]
18+
19+
@property
20+
def stack_id(self) -> str:
21+
return self["StackId"]
22+
23+
@property
24+
def request_id(self) -> str:
25+
return self["RequestId"]
26+
27+
@property
28+
def logical_resource_id(self) -> str:
29+
return self["LogicalResourceId"]
30+
31+
@property
32+
def physical_resource_id(self) -> str:
33+
return self.get("PhysicalResourceId") or ""
34+
35+
@property
36+
def resource_type(self) -> str:
37+
return self["ResourceType"]
38+
39+
@property
40+
def resource_properties(self) -> Dict[str, Any]:
41+
return self.get("ResourceProperties") or {}
42+
43+
@property
44+
def old_resource_properties(self) -> Dict[str, Any]:
45+
return self.get("OldResourceProperties") or {}

aws_lambda_powertools/utilities/parser/models/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
S3Model,
6969
S3RecordModel,
7070
)
71-
from .s3_batch_operation import S3BatchOperationJobModel, S3BatchOperationModel, S3BatchOperationTaskModel
71+
from .s3_batch_operation import (
72+
S3BatchOperationJobModel,
73+
S3BatchOperationModel,
74+
S3BatchOperationTaskModel,
75+
)
7276
from .s3_event_notification import (
7377
S3SqsEventNotificationModel,
7478
S3SqsEventNotificationRecordModel,

aws_lambda_powertools/utilities/parser/models/cloudformation_custom_resource.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ class CloudFormationCustomResourceCreateModel(CloudFormationCustomResourceBaseMo
2222

2323
class CloudFormationCustomResourceDeleteModel(CloudFormationCustomResourceBaseModel):
2424
request_type: Literal["Delete"] = Field(..., alias="RequestType")
25+
physical_resource_id: str = Field(..., alias="PhysicalResourceId")
2526

2627

2728
class CloudFormationCustomResourceUpdateModel(CloudFormationCustomResourceBaseModel):
2829
request_type: Literal["Update"] = Field(..., alias="RequestType")
30+
physical_resource_id: str = Field(..., alias="PhysicalResourceId")
2931
old_resource_properties: Union[Dict[str, Any], BaseModel, None] = Field(None, alias="OldResourceProperties")

docs/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# v9.1.18
2-
FROM squidfunk/mkdocs-material@sha256:5358893a04dc6ed0e267ef1c0c06abc5d6b00d13dd0fee703c978ef98d56fd53
2+
FROM squidfunk/mkdocs-material@sha256:8a87f059a80626324d012a72dc9a7b4275e89d1d6a83d1c55fed8063cc562fab
33
# pip-compile --generate-hashes --output-file=requirements.txt requirements.in
44
COPY requirements.txt /tmp/
55
RUN pip install --require-hashes -r /tmp/requirements.txt

0 commit comments

Comments
 (0)