Skip to content
Open
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
8 changes: 4 additions & 4 deletions aws_lambda_powertools/utilities/parser/envelopes/apigw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)


class ApiGatewayEnvelope(BaseEnvelope):
"""API Gateway envelope to extract data within body key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided
Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope
Returns
-------
Any
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Api Gateway model {APIGatewayProxyEventModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aws_lambda_powertools.utilities.parser.models import APIGatewayWebSocketMessageEventModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -16,19 +16,19 @@ class ApiGatewayWebSocketEnvelope(BaseEnvelope):
"""API Gateway WebSockets envelope to extract data within body key of messages routes
(not disconnect or connect)"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Any
T | None
Parsed detail payload with model provided
"""
logger.debug(
Expand Down
8 changes: 4 additions & 4 deletions aws_lambda_powertools/utilities/parser/envelopes/apigwv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from aws_lambda_powertools.utilities.parser.models import APIGatewayProxyEventV2Model

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)


class ApiGatewayV2Envelope(BaseEnvelope):
"""API Gateway V2 envelope to extract data within body key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Any
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Api Gateway model V2 {APIGatewayProxyEventV2Model}")
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/utilities/parser/envelopes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _parse(data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
return _parse_and_validate_event(data=data, adapter=adapter)

@abstractmethod
def parse(self, data: dict[str, Any] | Any | None, model: type[T]):
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | list[T | None] | None:
"""Implementation to parse data against envelope model, then against the data model

NOTE: Call `_parse` method to fully parse data with model provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from aws_lambda_powertools.utilities.parser.models import BedrockAgentEventModel, BedrockAgentFunctionEventModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)


class BedrockAgentEnvelope(BaseEnvelope):
"""Bedrock Agent envelope to extract data within input_text key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Model | None
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Bedrock Agent model {BedrockAgentEventModel}")
Expand All @@ -39,19 +39,19 @@ def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model
class BedrockAgentFunctionEnvelope(BaseEnvelope):
"""Bedrock Agent Function envelope to extract data within input_text key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Model | None
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Bedrock Agent Function model {BedrockAgentFunctionEventModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aws_lambda_powertools.utilities.parser.models import CloudWatchLogsModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -22,19 +22,19 @@ class CloudWatchLogsEnvelope(BaseEnvelope):
Note: The record will be parsed the same way so if model is str
"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> list[Model | None]:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> list[T | None]:
"""Parses records found with model provided
Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope
Returns
-------
list
list[T | None]
List of records parsed with model provided
"""
logger.debug(f"Parsing incoming data with SNS model {CloudWatchLogsModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aws_lambda_powertools.utilities.parser.models import DynamoDBStreamModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -19,19 +19,19 @@ class DynamoDBStreamEnvelope(BaseEnvelope):
length of the list is the record's amount in the original event.
"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> list[dict[str, Model | None]]:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> list[dict[str, T | None]]:
"""Parses DynamoDB Stream records found in either NewImage and OldImage with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
list
list[T | None]
List of dictionaries with NewImage and OldImage records parsed with model provided
"""
logger.debug(f"Parsing incoming data with DynamoDB Stream model {DynamoDBStreamModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from aws_lambda_powertools.utilities.parser.models import EventBridgeModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)


class EventBridgeEnvelope(BaseEnvelope):
"""EventBridge envelope to extract data within detail key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Any
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with EventBridge model {EventBridgeModel}")
Expand Down
8 changes: 4 additions & 4 deletions aws_lambda_powertools/utilities/parser/envelopes/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aws_lambda_powertools.utilities.parser.models import KafkaMskEventModel, KafkaSelfManagedEventModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -21,19 +21,19 @@ class KafkaEnvelope(BaseEnvelope):
all items in the list will be parsed as str and npt as JSON (and vice versa)
"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> list[Model | None]:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> list[T | None]:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
list
list[T | None]
List of records parsed with model provided
"""
event_source = cast(dict, data).get("eventSource")
Expand Down
8 changes: 4 additions & 4 deletions aws_lambda_powertools/utilities/parser/envelopes/kinesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aws_lambda_powertools.utilities.parser.models import KinesisDataStreamModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -24,19 +24,19 @@ class KinesisDataStreamEnvelope(BaseEnvelope):
all items in the list will be parsed as str and not as JSON (and vice versa)
"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> list[Model | None]:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> list[T | None]:
"""Parses records found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
list
list[T | None]
List of records parsed with model provided
"""
logger.debug(f"Parsing incoming data with Kinesis model {KinesisDataStreamModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aws_lambda_powertools.utilities.parser.models import KinesisFirehoseModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)

Expand All @@ -25,19 +25,19 @@ class KinesisFirehoseEnvelope(BaseEnvelope):
https://docs.aws.amazon.com/lambda/latest/dg/services-kinesisfirehose.html
"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> list[Model | None]:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> list[T | None]:
"""Parses records found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
list
list[T | None]
List of records parsed with model provided
"""
logger.debug(f"Parsing incoming data with Kinesis Firehose model {KinesisFirehoseModel}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
from aws_lambda_powertools.utilities.parser.models import LambdaFunctionUrlModel

if TYPE_CHECKING:
from aws_lambda_powertools.utilities.parser.types import Model
from aws_lambda_powertools.utilities.parser.types import T

logger = logging.getLogger(__name__)


class LambdaFunctionUrlEnvelope(BaseEnvelope):
"""Lambda function URL envelope to extract data within body key"""

def parse(self, data: dict[str, Any] | Any | None, model: type[Model]) -> Model | None:
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
"""Parses data found with model provided

Parameters
----------
data : dict
Lambda event to be parsed
model : type[Model]
model : type[T]
Data model provided to parse after extracting data using envelope

Returns
-------
Any
T | None
Parsed detail payload with model provided
"""
logger.debug(f"Parsing incoming data with Lambda function URL model {LambdaFunctionUrlModel}")
Expand Down
Loading