@@ -21,24 +21,36 @@ def parser(
21
21
22
22
As Lambda follows (event, context) signature we can remove some of the boilerplate
23
23
and also capture any exception any Lambda function throws as metadata.
24
- Event will be the parsed & validated BaseModel pydantic object of the input type "schema"
24
+ event will be the parsed and passed as a BaseModel pydantic class of the input type "schema"
25
+ to the lambda handler.
26
+ event will be extracted from the envelope in case envelope is not None.
27
+ In case envelope is None, the complete event is parsed to match the schema parameter BaseModel definition.
28
+ In case envelope is not None, first the event is parsed as the envelope's schema definition, and the user
29
+ message is extracted and parsed again as the schema parameter's definition.
25
30
26
31
Example
27
32
-------
28
33
**Lambda function using validation decorator**
29
34
30
35
@parser(schema=MyBusiness, envelope=envelopes.EVENTBRIDGE)
31
- def handler(event: inbound_schema_model , context: LambdaContext):
36
+ def handler(event: MyBusiness , context: LambdaContext):
32
37
...
33
38
34
39
Parameters
35
40
----------
36
- todo add
41
+ handler: input for lambda_handler_decorator, wraps the handler lambda
42
+ event: AWS event dictionary
43
+ context: AWS lambda context
44
+ schema: pydantic BaseModel class. This is the user data schema that will replace the event.
45
+ event parameter will be parsed and a new schema object will be created from it.
46
+ envelope: what envelope to extract the schema from, can be any AWS service that is currently
47
+ supported in the envelopes module. Can be None.
37
48
38
49
Raises
39
50
------
40
51
err
41
- TypeError or pydantic.ValidationError or any exception raised by the lambda handler itself
52
+ TypeError - in case event is None
53
+ pydantic.ValidationError - event fails validation, either of the envelope
42
54
"""
43
55
lambda_handler_name = handler .__name__
44
56
parsed_event = None
@@ -53,4 +65,4 @@ def handler(event: inbound_schema_model , context: LambdaContext):
53
65
parsed_event = parse_envelope (event , envelope , schema )
54
66
55
67
logger .debug (f"Calling handler { lambda_handler_name } " )
56
- handler (parsed_event , context )
68
+ return handler (parsed_event , context )
0 commit comments