Standalone lambda development ============================= Here is *standalone* lambda development description. More information about lambda types and differences of *standalone* and others available at `lambda types description <./lambda_types.html#standalone>`_. Standalone lambda requirements ------------------------------ Standalone lambda requirements has no extra requirements and determines only by user: if `lambda` suggests `Luna Events` usage - it requires `Luna Events` service. Standalone lambda development ----------------------------- The standalone lambda must be designed for detached from luna services requests processing, but it can access remote resources. The request to standalone lambda can be used by user next ways: .. code-block:: :caption: lambda_main.py from luna_lambda_tools import StandaloneLambdaRequest, logger async def main(request: StandaloneLambdaRequest) -> dict: logger.info(request.json) # print request json to log logger.info(request.getBody()) # print request body as raw bytes logger.info(request.headers) # print request headers logger.info(request.args) # print dictionary with query arguments ... It is required to use `StandaloneLambdaRequest` imported from `luna_lambda_tools` request as argument to `main` function. Standalone lambda examples -------------------------- - Here is an example of standalone lambda which works with numbers, that getting from external resources: .. literalinclude:: examples/201/standalone_lambda_development/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/standalone_lambda_development/make_request.py :caption: request example :language: python The `luna-lambda-tools` provides some stuff whose may be used to create standalone lambda: .. raw:: html
standalone lambda stuff description .. autosummary:: :toctree: _autosummary :recursive: luna_lambda_tools.public.standalone .. raw:: html
- The lambda example which gets face detection and estimate mask directly using the LUNA SDK (available at https://github.com/VisionLabs/lunasdk) LUNA python SDK must be added it to requirements.txt (`requirements description available here `_) .. literalinclude:: examples/201/standalone_lambda_sdk/lambda/requirements.txt :caption: requirements.txt .. note:: To develop lambda with lunasdk locally it needs LUNA FSDK python bindings to be installed previously. .. warning:: Such user lambda requires LUNA SDK data available from user lambda (the `fsdk/data` folder near the `lambda_main.py` main file) The LUNA SDK is available on VL release portal which must be extracted to `fsdk` folder (see archive file structure below). The only thing which is needed is *data* folder with used fsdk plans and config files (*faceengine.conf* and *runtime.conf*). It is recommended to not include not using plans from folder in archive to decrease result lambda image size. .. code-block:: :caption: Archive file structure with files required for the example ├──lambda_main.py ├──requirements.txt └──fsdk └──data ├──faceengine.conf ├──runtime.conf ├──FaceDet_v3_a5_cpu-avx2.plan ├──FaceDet_v3_redetect_v3_cpu-avx2.plan ├──LNet_precise_v2_cpu-avx2.plan ├──mask_clf_v3_cpu-avx2.plan └──slnet_v5_cpu-avx2.plan .. literalinclude:: examples/201/standalone_lambda_sdk/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/standalone_lambda_sdk/make_request.py :caption: request example :language: python - Lambda example which extracts faces from video and matches them with faces from the list: .. literalinclude:: examples/201/standalone_lambda_match_faces_from_video/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/standalone_lambda_match_faces_from_video/make_request.py :caption: request example :language: python - Lambda example which checks whether *Luna-Events* service is enabled and return reply with *on*/*off* text if *Luna-Events* is enabled or disabled respectively. Any other additional service (*Luna-Handlers*/*Luna-Sender*/etc) status can be checked in the same way, see `clients description `_ for details. .. literalinclude:: examples/201/service_disabled/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/service_disabled/make_request.py :caption: request example :language: python - Lambda example which serves static files, for example a custom UI. .. literalinclude:: examples/200/standalone_lambda_static_routes/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/200/standalone_lambda_static_routes/make_request.py :caption: request example :language: python .. code-block:: :caption: Archive file structure with files required for the example ├── lambda_main.py └── static └── my_ui └── index.html