forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent_source.py
39 lines (31 loc) · 1.07 KB
/
event_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)