Quick start guide

Quick start guide describes the simplest example that allows you to create and run your own lambda local or in 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 detailed lambdas description.

Local lambda execution

  1. Create virtual environment and install luna-lambda-tools package. (available at VL pypi)

    pip install --trusted-host pypi.visionlabs.ru --extra-index-url http://pypi.visionlabs.ru/root/public/+simple luna-lambda-tools
    
  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)}
    
  3. Create 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")
    
  4. Execute lambda using configuration from running instance of configurator:

    python run.py --luna-config http://127.0.0.1:5070/1
    

    All requests to lambda must use /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}
    

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 kubernetes cluster to work with. It is possible to use minikube as temporary solution for lambda development.

    To use minikube it needs to properly specify CLUSTER location setting, more information about configuration and settings available here.

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

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

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

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

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