-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-classes): decorator to instantiate data_classes and docs up…
…dates (#442)
- Loading branch information
Michael Brewer
authored
Jun 5, 2021
1 parent
31dc88c
commit 675cc24
Showing
7 changed files
with
339 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
aws_lambda_powertools/utilities/data_classes/event_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Any, Callable, Dict, Type | ||
|
||
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator | ||
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
@lambda_handler_decorator | ||
def event_source( | ||
handler: Callable[[Any, LambdaContext], Any], | ||
event: Dict[str, Any], | ||
context: LambdaContext, | ||
data_class: Type[DictWrapper], | ||
): | ||
"""Middleware to create an instance of the passed in event source data class | ||
Parameters | ||
---------- | ||
handler: Callable | ||
Lambda's handler | ||
event: Dict | ||
Lambda's Event | ||
context: Dict | ||
Lambda's Context | ||
data_class: Type[DictWrapper] | ||
Data class type to instantiate | ||
Example | ||
-------- | ||
**Sample usage** | ||
from aws_lambda_powertools.utilities.data_classes import S3Event, event_source | ||
@event_source(data_class=S3Event) | ||
def handler(event: S3Event, context): | ||
return {"key": event.object_key} | ||
""" | ||
return handler(data_class(event), context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.