-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/awslabs/aws-lambda-power…
…tools-python into develop * 'develop' of https://github.com/awslabs/aws-lambda-powertools-python: chore(deps): bump boto3 from 1.17.88 to 1.17.89 (#466) feat(data-classes): add AttributeValueType to DynamoDBStreamEvent (#462) chore(deps): bump boto3 from 1.17.87 to 1.17.88 (#463) chore(deps-dev): bump mkdocs-material from 7.1.6 to 7.1.7 (#464) feat(data-classes): decorator to instantiate data_classes and docs updates (#442) chore(deps): bump boto3 from 1.17.86 to 1.17.87 (#459)
- Loading branch information
Showing
10 changed files
with
516 additions
and
231 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
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.