-
Notifications
You must be signed in to change notification settings - Fork 421
/
Copy pathevent_source.py
45 lines (34 loc) · 1.18 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
40
41
42
43
44
45
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
if TYPE_CHECKING:
from collections.abc import Callable
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[str, Any]
Lambda's Event
context: LambdaContext
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)