diff --git a/aws_lambda_powertools/logging/formatter.py b/aws_lambda_powertools/logging/formatter.py index 0b3cb62cc61..647abf33a8a 100644 --- a/aws_lambda_powertools/logging/formatter.py +++ b/aws_lambda_powertools/logging/formatter.py @@ -37,7 +37,8 @@ def __init__(self, **kwargs): self.format_dict.update(self._build_root_keys(**kwargs)) - def _build_root_keys(self, **kwargs): + @staticmethod + def _build_root_keys(**kwargs): return { "level": "%(levelname)s", "location": "%(funcName)s:%(lineno)d", diff --git a/aws_lambda_powertools/utilities/batch/base.py b/aws_lambda_powertools/utilities/batch/base.py index 19b627704f9..38fc1ca75fc 100644 --- a/aws_lambda_powertools/utilities/batch/base.py +++ b/aws_lambda_powertools/utilities/batch/base.py @@ -6,7 +6,7 @@ import logging from abc import ABC, abstractmethod -from typing import Any, Callable, Dict, Iterable, List, Tuple +from typing import Any, Callable, Dict, List, Tuple from aws_lambda_powertools.middleware_factory import lambda_handler_decorator @@ -57,14 +57,14 @@ def __enter__(self): def __exit__(self, exception_type, exception_value, traceback): self._clean() - def __call__(self, records: Iterable[Any], handler: Callable): + def __call__(self, records: List[Any], handler: Callable): """ Set instance attributes before execution Parameters ---------- - records: Iterable[Any] - Iterable with objects to be processed. + records: List[Any] + List with objects to be processed. handler: Callable Callable to process "records" entries. """ @@ -95,7 +95,7 @@ def failure_handler(self, record: Any, exception: Exception): "fail", exceptions args, original record """ entry = ("fail", exception.args, record) - logger.debug("Record processing exception: ", exception) + logger.debug(f"Record processing exception: {exception}") self.exceptions.append(exception) self.fail_messages.append(record) return entry @@ -124,7 +124,7 @@ def batch_processor( Examples -------- **Processes Lambda's event with PartialSQSProcessor** - >>> from aws_lambda_powertools.utilities.batch import batch_processor + >>> from aws_lambda_powertools.utilities.batch import batch_processor, PartialSQSProcessor >>> >>> def record_handler(record): >>> return record["body"] diff --git a/aws_lambda_powertools/utilities/typing/lambda_cognito_identity.py b/aws_lambda_powertools/utilities/typing/lambda_cognito_identity.py index 9cced6a59c2..06679269330 100644 --- a/aws_lambda_powertools/utilities/typing/lambda_cognito_identity.py +++ b/aws_lambda_powertools/utilities/typing/lambda_cognito_identity.py @@ -2,9 +2,7 @@ class LambdaCognitoIdentity(object): - """ - Information about the Amazon Cognito identity that authorized the request. - """ + """Information about the Amazon Cognito identity that authorized the request.""" _cognito_identity_id: str _cognito_identity_pool_id: str diff --git a/aws_lambda_powertools/utilities/typing/lambda_context.py b/aws_lambda_powertools/utilities/typing/lambda_context.py index 6db486412a3..b132fe413bc 100644 --- a/aws_lambda_powertools/utilities/typing/lambda_context.py +++ b/aws_lambda_powertools/utilities/typing/lambda_context.py @@ -10,6 +10,7 @@ class LambdaContext(object): ------- **A Lambda function using LambdaContext** + >>> from typing import Any, Dict >>> from aws_lambda_powertools.utilities.typing import LambdaContext >>> >>> def handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]: diff --git a/docs/content/utilities/batch.mdx b/docs/content/utilities/batch.mdx index a5ed8c90ff6..e8fe73dc4ff 100644 --- a/docs/content/utilities/batch.mdx +++ b/docs/content/utilities/batch.mdx @@ -9,7 +9,7 @@ The SQS batch processing utility provides a way to handle partial failures when **Key Features** -* Prevent succesfully processed messages being returned to SQS +* Prevent successfully processed messages being returned to SQS * Simple interface for individually processing messages from a batch * Build your own batch processor using the base classes diff --git a/tests/functional/test_utilities_typing.py b/tests/functional/test_utilities_typing.py index b2b4a752d9f..8522cfcbf99 100644 --- a/tests/functional/test_utilities_typing.py +++ b/tests/functional/test_utilities_typing.py @@ -1,6 +1,51 @@ from aws_lambda_powertools.utilities.typing import LambdaContext +from aws_lambda_powertools.utilities.typing.lambda_client_context import LambdaClientContext +from aws_lambda_powertools.utilities.typing.lambda_client_context_mobile_client import LambdaClientContextMobileClient +from aws_lambda_powertools.utilities.typing.lambda_cognito_identity import LambdaCognitoIdentity def test_typing(): context = LambdaContext() + context._function_name = "_function_name" + context._function_version = "_function_version" + context._invoked_function_arn = "_invoked_function_arn" + context._memory_limit_in_mb = "_memory_limit_in_mb" + context._aws_request_id = "_aws_request_id" + context._log_group_name = "_log_group_name" + context._log_stream_name = "_log_stream_name" + identity = LambdaCognitoIdentity() + identity._cognito_identity_id = "_cognito_identity_id" + identity._cognito_identity_pool_id = "_cognito_identity_pool_id" + context._identity = identity + client_context = LambdaClientContext() + client = LambdaClientContextMobileClient() + client._installation_id = "_installation_id" + client._app_title = "_app_title" + client._app_version_name = "_app_version_name" + client._app_version_code = "_app_version_code" + client._app_package_name = "_app_package_name" + client_context._client = client + client_context._custom = {} + client_context._env = {} + context._client_context = client_context + + assert context.function_name == context._function_name + assert context.function_version == context._function_version + assert context.invoked_function_arn == context._invoked_function_arn + assert context.memory_limit_in_mb == context._memory_limit_in_mb + assert context.aws_request_id == context._aws_request_id + assert context.log_group_name == context._log_group_name + assert context.log_stream_name == context._log_stream_name + assert context.identity == context._identity + assert context.identity.cognito_identity_id == identity._cognito_identity_id + assert context.identity.cognito_identity_pool_id == identity._cognito_identity_pool_id + assert context.client_context == context._client_context + assert context.client_context.client == client_context._client + assert context.client_context.client.installation_id == client._installation_id + assert context.client_context.client.app_title == client._app_title + assert context.client_context.client.app_version_name == client._app_version_name + assert context.client_context.client.app_version_code == client._app_version_code + assert context.client_context.client.app_package_name == client._app_package_name + assert context.client_context.custom == client_context._custom + assert context.client_context.env == client_context._env assert context.get_remaining_time_in_millis() == 0