@@ -19,42 +19,43 @@ def parser(
19
19
schema : BaseModel ,
20
20
envelope : Optional [BaseEnvelope ] = None ,
21
21
) -> Any :
22
+ # noinspection SpellCheckingInspection,SpellCheckingInspection
22
23
"""Decorator to conduct advanced parsing & validation for lambda handlers events
23
24
24
- As Lambda follows (event, context) signature we can remove some of the boilerplate
25
- and also capture any exception any Lambda function throws as metadata.
26
- event will be the parsed and passed as a BaseModel pydantic class of the input type "schema"
27
- to the lambda handler.
28
- event will be extracted from the envelope in case envelope is not None.
29
- In case envelope is None, the complete event is parsed to match the schema parameter BaseModel definition.
30
- In case envelope is not None, first the event is parsed as the envelope's schema definition, and the user
31
- message is extracted and parsed again as the schema parameter's definition.
25
+ As Lambda follows (event, context) signature we can remove some of the boilerplate
26
+ and also capture any exception any Lambda function throws as metadata.
27
+ event will be the parsed and passed as a BaseModel pydantic class of the input type "schema"
28
+ to the lambda handler.
29
+ event will be extracted from the envelope in case envelope is not None.
30
+ In case envelope is None, the complete event is parsed to match the schema parameter BaseModel definition.
31
+ In case envelope is not None, first the event is parsed as the envelope's schema definition, and the user
32
+ message is extracted and parsed again as the schema parameter's definition.
32
33
33
- Example
34
- -------
35
- **Lambda function using validation decorator**
34
+ Example
35
+ -------
36
+ **Lambda function using validation decorator**
36
37
37
- @parser(schema=MyBusiness, envelope=envelopes.EVENTBRIDGE)
38
- def handler(event: MyBusiness , context: LambdaContext):
39
- ...
38
+ @parser(schema=MyBusiness, envelope=envelopes.EVENTBRIDGE)
39
+ def handler(event: MyBusiness , context: LambdaContext):
40
+ ...
40
41
41
- Parameters
42
- ----------
43
- handler: input for lambda_handler_decorator, wraps the handler lambda
44
- event: AWS event dictionary
45
- context: AWS lambda context
46
- schema: pydantic BaseModel class. This is the user data schema that will replace the event.
47
- event parameter will be parsed and a new schema object will be created from it.
48
- envelope: what envelope to extract the schema from, can be any AWS service that is currently
49
- supported in the envelopes module. Can be None.
42
+ Parameters
43
+ ----------
44
+ handler: input for lambda_handler_decorator, wraps the handler lambda
45
+ event: AWS event dictionary
46
+ context: AWS lambda context
47
+ schema: pydantic BaseModel class. This is the user data schema that will replace the event.
48
+ event parameter will be parsed and a new schema object will be created from it.
49
+ envelope: what envelope to extract the schema from, can be any AWS service that is currently
50
+ supported in the envelopes module. Can be None.
50
51
51
- Raises
52
- ------
53
- SchemaValidationError
54
- When input event doesn't conform with schema provided
55
- InvalidSchemaTypeError
56
- When schema given does not implement BaseModel
57
- """
52
+ Raises
53
+ ------
54
+ SchemaValidationError
55
+ When input event doesn't conform with schema provided
56
+ InvalidSchemaTypeError
57
+ When schema given does not implement BaseModel
58
+ """
58
59
if envelope is None :
59
60
try :
60
61
logger .debug ("Parsing and validating event schema; no envelope used" )
0 commit comments