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

  1. 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

    pip install --trusted-host pypi.visionlabs.ru --extra-index-url http://pypi.visionlabs.ru/root/public/+simple luna-lambda-package-helper[base]
    
  2. Create the main file:

    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.

  1. Execute the lambda using the starting script:

    run_lambda standalone
    
  2. Or create a file for lambda local execution (it only needs to execute lambda local):

    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.

  1. Execute the lambda using the default configuration:

    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:

    curl -X POST "http://127.0.0.1:8000/main" --data-binary 123
    
    >>> {"request_length_in_bytes":3}
    
  2. Or run the lambda with a custom config file:

    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:

    python run.py --config /path/to/config/file/config.conf
    

    or

    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.

  1. 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.

    There are also some additional requirements for lambda and the kubernetes cluster.

  2. Install and execute Luna-Lambda (see the installation chapter for details).

  3. Create a zip-archive with the lambda_main.py file from previous step of quick start guide.

  4. Create the lambda using zip-archive by making a lambda creation request.

  5. Wait for the lambda starts and check its availability, see the lambda usage chapter for details.