Skip to content

Commit bd270ca

Browse files
committed
Add a dosctring and example use case for the LambdaHandler base class
1 parent 0591f2b commit bd270ca

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/aibs_informatics_aws_lambda/common/handler.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@ class LambdaHandler(
4040
BaseExecutor[REQUEST, RESPONSE],
4141
Generic[REQUEST, RESPONSE],
4242
):
43+
"""Inherit from the LambdaHandler class to create a custom strongly typed lambda handler
44+
that expects a REQUEST object and returns a RESPONSE object that follow the `ModelProtocol`.
45+
46+
Example usage:
47+
48+
```python
49+
from aibs_informatics_aps_utils.models.base.pydantic_model_base import PydanticModel
50+
51+
class MyLambdaRequestModel(PydanticModel):
52+
first_input_field_to_lambda: str
53+
second_input_field_to_lambda: int
54+
55+
# Example of if your lambda doesn't return a response
56+
# class MyLambdaResponseModel(PydanticModel):
57+
# pass
58+
59+
# Example if your lambda returns a simple response
60+
class MyLambdaResponseModel(PydanticModel):
61+
lambda_specific_return_value: int
62+
63+
@dataclass
64+
class MyCustomLambdaHandler(LambdaHandler[MyLambdaRequestModel, MyLambdaResponseModel]):
65+
...
66+
67+
```
68+
69+
NOTE: Classes that inherit from `LambdaHandler` MUST specify the REQUEST and RESPONSE models!
70+
"""
71+
4372
def __post_init__(self):
4473
self.context = LambdaContext()
4574
super().__post_init__()

0 commit comments

Comments
 (0)