Skip to content

chore(batch): Housekeeping for recent changes #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aws_lambda_powertools/logging/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions aws_lambda_powertools/utilities/batch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me we need to prioritise a minter for NumPy docstrings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heitorlessa - sure


_cognito_identity_id: str
_cognito_identity_pool_id: str
Expand Down
1 change: 1 addition & 0 deletions aws_lambda_powertools/utilities/typing/lambda_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/utilities/batch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 45 additions & 0 deletions tests/functional/test_utilities_typing.py
Original file line number Diff line number Diff line change
@@ -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