Skip to content

Commit 06174b6

Browse files
author
Michael Brewer
committed
Merge branch 'develop' into feat-apigw-prefix
2 parents 7e85487 + 61e7f2d commit 06174b6

File tree

10 files changed

+38
-29
lines changed

10 files changed

+38
-29
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,10 @@ def _resolve(self) -> ResponseBuilder:
531531
for route in self._routes:
532532
if method != route.method:
533533
continue
534-
match: Optional[re.Match] = route.rule.match(path)
535-
if match:
534+
match_results: Optional[re.Match] = route.rule.match(path)
535+
if match_results:
536536
logger.debug("Found a registered route. Calling function")
537-
return self._call_route(route, match.groupdict()) # pass fn args
537+
return self._call_route(route, match_results.groupdict()) # pass fn args
538538

539539
logger.debug(f"No match found for path {path} and method {method}")
540540
return self._not_found(method)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Shared exceptions that don't belong to a single utility"""
2+
3+
4+
class InvalidEnvelopeExpressionError(Exception):
5+
"""When JMESPath fails to parse expression"""

aws_lambda_powertools/shared/jmespath_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import base64
22
import gzip
33
import json
4+
import logging
45
from typing import Any, Dict, Optional, Union
56

67
import jmespath
78
from jmespath.exceptions import LexerError
89

9-
from aws_lambda_powertools.utilities.validation import InvalidEnvelopeExpressionError
10-
from aws_lambda_powertools.utilities.validation.base import logger
10+
from aws_lambda_powertools.exceptions import InvalidEnvelopeExpressionError
11+
12+
logger = logging.getLogger(__name__)
1113

1214

1315
class PowertoolsFunctions(jmespath.functions.Functions):
@@ -27,7 +29,7 @@ def _func_powertools_base64_gzip(self, value):
2729
return uncompressed.decode()
2830

2931

30-
def unwrap_event_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any:
32+
def extract_data_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any:
3133
"""Searches data using JMESPath expression
3234
3335
Parameters

aws_lambda_powertools/utilities/data_classes/appsync_authorizer_event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ class AppSyncAuthorizerResponse:
6868
is authorized to make calls to the GraphQL API. If this value is
6969
true, execution of the GraphQL API continues. If this value is false,
7070
an UnauthorizedException is raised
71-
max_age: Optional[int]
71+
max_age: int, optional
7272
Set the ttlOverride. The number of seconds that the response should be
7373
cached for. If no value is returned, the value from the API (if configured)
7474
or the default of 300 seconds (five minutes) is used. If this is 0, the response
7575
is not cached.
76-
resolver_context: Optional[Dict[str, Any]]
76+
resolver_context: Dict[str, Any], optional
7777
A JSON object visible as `$ctx.identity.resolverContext` in resolver templates
7878
7979
The resolverContext object only supports key-value pairs. Nested keys are not supported.
8080
8181
Warning: The total size of this JSON object must not exceed 5MB.
82-
deny_fields: Optional[List[str]]
82+
deny_fields: List[str], optional
8383
A list of fields that will be set to `null` regardless of the resolver's return.
8484
8585
A field is either `TypeName.FieldName`, or an ARN such as

aws_lambda_powertools/utilities/feature_flags/appconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_configuration(self) -> Dict[str, Any]:
8080
)
8181

8282
if self.envelope:
83-
config = jmespath_utils.unwrap_event_from_envelope(
83+
config = jmespath_utils.extract_data_from_envelope(
8484
data=config, envelope=self.envelope, jmespath_options=self.jmespath_options
8585
)
8686

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from ...exceptions import InvalidEnvelopeExpressionError
2+
3+
14
class SchemaValidationError(Exception):
25
"""When serialization fail schema validation"""
36

@@ -6,5 +9,4 @@ class InvalidSchemaFormatError(Exception):
69
"""When JSON Schema is in invalid format"""
710

811

9-
class InvalidEnvelopeExpressionError(Exception):
10-
"""When JMESPath fails to parse expression"""
12+
__all__ = ["SchemaValidationError", "InvalidSchemaFormatError", "InvalidEnvelopeExpressionError"]

aws_lambda_powertools/utilities/validation/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def handler(event, context):
117117
When JMESPath expression to unwrap event is invalid
118118
"""
119119
if envelope:
120-
event = jmespath_utils.unwrap_event_from_envelope(
120+
event = jmespath_utils.extract_data_from_envelope(
121121
data=event, envelope=envelope, jmespath_options=jmespath_options
122122
)
123123

@@ -219,7 +219,7 @@ def handler(event, context):
219219
When JMESPath expression to unwrap event is invalid
220220
"""
221221
if envelope:
222-
event = jmespath_utils.unwrap_event_from_envelope(
222+
event = jmespath_utils.extract_data_from_envelope(
223223
data=event, envelope=envelope, jmespath_options=jmespath_options
224224
)
225225

poetry.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ black = "^20.8b1"
3434
flake8 = "^3.9.0"
3535
flake8-black = "^0.2.3"
3636
flake8-builtins = "^1.5.3"
37-
flake8-comprehensions = "^3.6.0"
37+
flake8-comprehensions = "^3.6.1"
3838
flake8-debugger = "^4.0.0"
3939
flake8-fixme = "^1.1.1"
4040
flake8-isort = "^4.0.0"
@@ -60,7 +60,7 @@ pydantic = ["pydantic", "email-validator"]
6060

6161
[tool.coverage.run]
6262
source = ["aws_lambda_powertools"]
63-
omit = ["tests/*"]
63+
omit = ["tests/*", "aws_lambda_powertools/exceptions/*"]
6464
branch = true
6565

6666
[tool.coverage.html]

tests/functional/idempotency/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from botocore.config import Config
1212
from jmespath import functions
1313

14-
from aws_lambda_powertools.shared.jmespath_utils import unwrap_event_from_envelope
14+
from aws_lambda_powertools.shared.jmespath_utils import extract_data_from_envelope
1515
from aws_lambda_powertools.shared.json_encoder import Encoder
1616
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer
1717
from aws_lambda_powertools.utilities.idempotency.idempotency import IdempotencyConfig
@@ -149,7 +149,7 @@ def hashed_idempotency_key(lambda_apigw_event, default_jmespath, lambda_context)
149149

150150
@pytest.fixture
151151
def hashed_idempotency_key_with_envelope(lambda_apigw_event):
152-
event = unwrap_event_from_envelope(
152+
event = extract_data_from_envelope(
153153
data=lambda_apigw_event, envelope=envelopes.API_GATEWAY_HTTP, jmespath_options={}
154154
)
155155
return "test-func#" + hashlib.md5(json.dumps(event).encode()).hexdigest()

0 commit comments

Comments
 (0)