Quick start guide ================= Quick start guide describes the simplest example that allows you to create and run your own lambda local or in a kubernetes cluster. .. note:: Here and below will be presented the simplest useless example of lambda. For applicable in real life cases, detailed requirements, lifecycle and other description see the `detailed lambdas description `_. Local lambda execution ---------------------- #) Create a virtual environment and install the `luna-lambda-package-helper[base]` package. (available on `the company's pypi `_). This will install `luna-lambda-tools` .. code-block:: bash pip install --trusted-host pypi.visionlabs.ru --extra-index-url http://pypi.visionlabs.ru/root/public/+simple luna-lambda-package-helper[base] #) Create the main file: .. code-block:: :caption: lambda_main.py from luna_lambda_tools import StandaloneLambdaRequest async def main(request: StandaloneLambdaRequest) -> dict: return {"request_length_in_bytes": len(request.body)} .. note:: Another lambda types required another `lambda_main.py` content. For more information, see the `lambda types chapter `_. #) Execute the lambda using the starting script: .. code-block:: bash run_lambda standalone #) Or create a file for lambda local execution (it only needs to execute lambda local): .. code-block:: :caption: run.py from luna_lambda_tools.public.run import run if __name__ == "__main__": run(lambdaType="standalone") .. note:: Another lambda types required another `lambdaType` value. For more information, see the `lambda types chapter `_. #) Execute the lambda using the default configuration: .. code-block:: bash python run.py All requests to the lambda must use the `/main` endpoint. If there no errors on previous steps, when sending the following request, the following response will be received: .. code-block:: bash curl -X POST "http://127.0.0.1:8000/main" --data-binary 123 >>> {"request_length_in_bytes":3} #) Or run the lambda with a custom config file: .. code-block:: :caption: config.conf [LUNA_MONITORING] SEND_DATA_FOR_MONITORING = 1 [LUNA_CONFIGURATOR] USE_CONFIGURATOR = 0 [LUNA_LAMBDA_UNIT_LOGGER] FOLDER_WITH_LOGS = ./ LOG_LEVEL = INFO LOG_TIME = LOCAL MAX_LOG_FILE_SIZE = 1024 LOG_TO_STDOUT = 1 LOG_TO_FILE = 0 MULTILINE_STACK_TRACE = 1 FORMAT = default ... .. note:: Set `USE_CONFIGURATOR=0` to prevent the lambda from reaching the `Luna-Configurator` service. Set `SEND_DATA_FOR_MONITORING=0` to prevent the lambda from trying to reach the monitoring storage. Some lambda types require certain services to be reachable, read your lambda type description to find out more. Launch the lambda: .. code-block:: bash python run.py --config /path/to/config/file/config.conf or .. code-block:: bash run_lambda standalone --config /path/to/config/file/config.conf .. note:: Another configuration loading possibilities described at `configuration chapter `_ (configuration loading principle is the same for the *Luna-Lambda* service and for each *lambda*). Deploy lambda using `Luna lambda` into kubernetes cluster --------------------------------------------------------- .. note:: `Luna-Api` provides necessary methods to create and use lambdas at `lambda` section of openapi documentation. #) `Luna-Lambda` requires a kubernetes cluster to work with. It is possible to use `minikube `_ as a temporary solution for lambda development. To use minikube it needs to properly specify *CLUSTER* location setting, more information about configuration and settings is available `here <./config.html#configuration-requirements>`_. There are also some additional requirements `for lambda <./lambda_requirements.html#lambda-general-python-code-requirements>`_ and the `kubernetes cluster <./lambda_requirements.html#kubernetes-cluster-requirements>`_. #) Install and execute `Luna-Lambda` (see the `installation chapter <./install.html>`_ for details). #) Create a zip-archive with the `lambda_main.py` file from previous step of quick start guide. #) Create the lambda using zip-archive by making a `lambda creation request <./_static/api.html#operation/createLambda>`_. #) Wait for the lambda starts and check its availability, see the `lambda usage chapter <./lambda_usage.html>`_ for details.