Skip to content

Commit b8a8ab5

Browse files
chore(batch): Housekeeping for recent changes (#157)
* chore(batch): Housekeeping Changes: * base.py - `records` can't just be iterable as we reference it by `__getitem__` * base.py - logger.debugger is expecting a `%s` * docs - Typos in the docs * formatter.py - `_build_root_keys` can be a static method * tests(typing): add some test coverage Changes: * Make docstrings consistent * Add missing test cases (although this might be trivial) * fix: use f-string for consistency
1 parent 80a7602 commit b8a8ab5

File tree

6 files changed

+56
-11
lines changed

6 files changed

+56
-11
lines changed

aws_lambda_powertools/logging/formatter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def __init__(self, **kwargs):
3737

3838
self.format_dict.update(self._build_root_keys(**kwargs))
3939

40-
def _build_root_keys(self, **kwargs):
40+
@staticmethod
41+
def _build_root_keys(**kwargs):
4142
return {
4243
"level": "%(levelname)s",
4344
"location": "%(funcName)s:%(lineno)d",

aws_lambda_powertools/utilities/batch/base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import logging
88
from abc import ABC, abstractmethod
9-
from typing import Any, Callable, Dict, Iterable, List, Tuple
9+
from typing import Any, Callable, Dict, List, Tuple
1010

1111
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
1212

@@ -57,14 +57,14 @@ def __enter__(self):
5757
def __exit__(self, exception_type, exception_value, traceback):
5858
self._clean()
5959

60-
def __call__(self, records: Iterable[Any], handler: Callable):
60+
def __call__(self, records: List[Any], handler: Callable):
6161
"""
6262
Set instance attributes before execution
6363
6464
Parameters
6565
----------
66-
records: Iterable[Any]
67-
Iterable with objects to be processed.
66+
records: List[Any]
67+
List with objects to be processed.
6868
handler: Callable
6969
Callable to process "records" entries.
7070
"""
@@ -95,7 +95,7 @@ def failure_handler(self, record: Any, exception: Exception):
9595
"fail", exceptions args, original record
9696
"""
9797
entry = ("fail", exception.args, record)
98-
logger.debug("Record processing exception: ", exception)
98+
logger.debug(f"Record processing exception: {exception}")
9999
self.exceptions.append(exception)
100100
self.fail_messages.append(record)
101101
return entry
@@ -124,7 +124,7 @@ def batch_processor(
124124
Examples
125125
--------
126126
**Processes Lambda's event with PartialSQSProcessor**
127-
>>> from aws_lambda_powertools.utilities.batch import batch_processor
127+
>>> from aws_lambda_powertools.utilities.batch import batch_processor, PartialSQSProcessor
128128
>>>
129129
>>> def record_handler(record):
130130
>>> return record["body"]

aws_lambda_powertools/utilities/typing/lambda_cognito_identity.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33

44
class LambdaCognitoIdentity(object):
5-
"""
6-
Information about the Amazon Cognito identity that authorized the request.
7-
"""
5+
"""Information about the Amazon Cognito identity that authorized the request."""
86

97
_cognito_identity_id: str
108
_cognito_identity_pool_id: str

aws_lambda_powertools/utilities/typing/lambda_context.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class LambdaContext(object):
1010
-------
1111
**A Lambda function using LambdaContext**
1212
13+
>>> from typing import Any, Dict
1314
>>> from aws_lambda_powertools.utilities.typing import LambdaContext
1415
>>>
1516
>>> def handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]:

docs/content/utilities/batch.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The SQS batch processing utility provides a way to handle partial failures when
99

1010
**Key Features**
1111

12-
* Prevent succesfully processed messages being returned to SQS
12+
* Prevent successfully processed messages being returned to SQS
1313
* Simple interface for individually processing messages from a batch
1414
* Build your own batch processor using the base classes
1515

+45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
from aws_lambda_powertools.utilities.typing import LambdaContext
2+
from aws_lambda_powertools.utilities.typing.lambda_client_context import LambdaClientContext
3+
from aws_lambda_powertools.utilities.typing.lambda_client_context_mobile_client import LambdaClientContextMobileClient
4+
from aws_lambda_powertools.utilities.typing.lambda_cognito_identity import LambdaCognitoIdentity
25

36

47
def test_typing():
58
context = LambdaContext()
9+
context._function_name = "_function_name"
10+
context._function_version = "_function_version"
11+
context._invoked_function_arn = "_invoked_function_arn"
12+
context._memory_limit_in_mb = "_memory_limit_in_mb"
13+
context._aws_request_id = "_aws_request_id"
14+
context._log_group_name = "_log_group_name"
15+
context._log_stream_name = "_log_stream_name"
16+
identity = LambdaCognitoIdentity()
17+
identity._cognito_identity_id = "_cognito_identity_id"
18+
identity._cognito_identity_pool_id = "_cognito_identity_pool_id"
19+
context._identity = identity
20+
client_context = LambdaClientContext()
21+
client = LambdaClientContextMobileClient()
22+
client._installation_id = "_installation_id"
23+
client._app_title = "_app_title"
24+
client._app_version_name = "_app_version_name"
25+
client._app_version_code = "_app_version_code"
26+
client._app_package_name = "_app_package_name"
27+
client_context._client = client
28+
client_context._custom = {}
29+
client_context._env = {}
30+
context._client_context = client_context
31+
32+
assert context.function_name == context._function_name
33+
assert context.function_version == context._function_version
34+
assert context.invoked_function_arn == context._invoked_function_arn
35+
assert context.memory_limit_in_mb == context._memory_limit_in_mb
36+
assert context.aws_request_id == context._aws_request_id
37+
assert context.log_group_name == context._log_group_name
38+
assert context.log_stream_name == context._log_stream_name
39+
assert context.identity == context._identity
40+
assert context.identity.cognito_identity_id == identity._cognito_identity_id
41+
assert context.identity.cognito_identity_pool_id == identity._cognito_identity_pool_id
42+
assert context.client_context == context._client_context
43+
assert context.client_context.client == client_context._client
44+
assert context.client_context.client.installation_id == client._installation_id
45+
assert context.client_context.client.app_title == client._app_title
46+
assert context.client_context.client.app_version_name == client._app_version_name
47+
assert context.client_context.client.app_version_code == client._app_version_code
48+
assert context.client_context.client.app_package_name == client._app_package_name
49+
assert context.client_context.custom == client_context._custom
50+
assert context.client_context.env == client_context._env
651
assert context.get_remaining_time_in_millis() == 0

0 commit comments

Comments
 (0)