-
Notifications
You must be signed in to change notification settings - Fork 2
FAQs (Frequently Asked Questions)
Álvaro Puente edited this page Sep 16, 2025
·
6 revisions
In case the user wants to use third party libraries un the user application, these are the steps to be followed:
$ source serverless-env/bin/activate
(serverless-env) $
(serverless-env) $ pip install pandas
Collecting pandas
Downloading pandas-2.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB)
|████████████████████████████████| 13.0 MB 935 kB/s
Requirement already satisfied: numpy<2,>=1.22.4 in ./serverless-env/lib/python3.10/site-packages (from pandas) (1.26.4)
Collecting tzdata>=2022.7
Downloading tzdata-2024.1-py2.py3-none-any.whl (345 kB)
|████████████████████████████████| 345 kB 21.6 MB/s
Collecting python-dateutil>=2.8.2
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting pytz>=2020.1
Downloading pytz-2024.1-py2.py3-none-any.whl (505 kB)
|████████████████████████████████| 505 kB 29.6 MB/s
Requirement already satisfied: six>=1.5 in ./serverless-env/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
Installing collected packages: tzdata, pytz, python-dateutil, pandas
Successfully installed pandas-2.2.1 python-dateutil-2.8.2 pytz-2024.1 tzdata-2024.1
B) Install the dependency in the virtual environment of the Flavour you are using. For that, there are two options;
B.1) Install it through the start script of the Context of the Flavour's VM template (Simple solution):
Click on Templates -> VMs -> Select the template your flavour is using.
Click on Update, on the following screen:

Go to 'Context' tab, and in the 'start script' box, add the command shown in the next picture, replacing pandas, with the dependency(ies) you want to add. (* Please note that this needs to be done right after the virtual environment gets activates with the source command)

B.2) Install it/them in the image of the flavour you are using (Complex solution)
[* be aware that you will need privileged user permissions to perform many of these actions]:
- First of all, you need to create a SR of the Flavour you are trying to modify, through the Device Runtime library or using the COGNIT dashboard.
- Go to
cd /root/serverless-runtime, and activate the virtual environment in that folder:source serverless-env/bin/activate.
You can perform the installation of the dependency(ies) you need, such as:
pip install pandas
- Once this is done, you can save the VM instance's current state as an image within Cognit:
First, save the current instance's image clicking on Instances -> VMs -> Click on the instance where you performed the changes,
Once you are in the VM instance info screen, go to the Storage tab, and click on the little floppy disk icon, as shown in:

- Name the disk with a meaningful name, so you can identify it in the future easily:

- Go to the VM template's Storage section by clicking on Templates -> VMs -> Select the template you are using with your Flavour -> Click on Update
Then, once you are in the Storage tab, you can choose the disk image you just created in the previous step:
C) Once you have installed the dependencies you needed, running an example such as the following should let you use that third party library:
Minimal example:
def pandas_func():
import pandas
return pandas.__version__
# This is where the user can define the FLAVOUR to be used within COGNIT to deploy the FaaS node.
sr_conf.faas_flavour = "Nature"
sr_conf.geolocation = "Atlantide"
# Request the creation of the Serverless Runtime to the COGNIT Provisioning Engine
try:
my_cognit_runtime = ServerlessRuntimeContext(config_path="./examples/cognit-wildfire.yml")
# Perform the request of generating and assigning a Serverless Runtime to this Serverless Runtime context.
ret = my_cognit_runtime.create(sr_conf)
except Exception as e:
print("Error in config file content: {}".format(e))
exit(1)
# Wait until the runtime is ready
# Checks the status of the request of creating the Serverless Runtime, and sleeps 1 sec if still not available.
while my_cognit_runtime.status != FaaSState.RUNNING:
time.sleep(1)
print("COGNIT Serverless Runtime ready!")
# Example offloading a function call to the Serverless Runtime
result = my_cognit_runtime.call_sync(pandas_func)
- (* Note that the import of the third party library should go within the function)
Execution output:
$ python3 -i examples/minimal_offload_sync.py
[2024-02-26 10:21:18,564] [WARNING] [serverless_runtime_context.py::55] {'ip': '193.145.247.253', 'city': 'Arrasate / Mondragón', 'region': 'Basque Country', 'country': 'ES', 'loc': '43.0644,-2.4898', 'org': 'AS766 Entidad Publica Empresarial Red.es', 'postal': '20500', 'timezone': 'Europe/Madrid', 'readme': 'https://ipinfo.io/missingauth'}
[2024-02-26 10:21:18,565] [DEBUG] [_prov_engine_client.py::40] Create GET's URL for latency e: http://cognit-lab.sovereignedge.eu:1337
[2024-02-26 10:21:19,007] [DEBUG] [_prov_engine_client.py::46] Response from GET for latency Create: <Response [200]>
[2024-02-26 10:21:19,008] [WARNING] [_prov_engine_client.py::49] Latency to Provisioning Engine is: 0.280872
[2024-02-26 10:21:19,011] [WARNING] [serverless_runtime_context.py::151] ¡ATTENTION! Your Requirements ENERGY_RENEWABLE=YES are NOT being sent to COGNIT Scheduler.
[2024-02-26 10:21:19,012] [WARNING] [serverless_runtime_context.py::153] ¡ATTENTION! This is a temporary measure until Schduler is working full steam.
[2024-02-26 10:21:19,012] [WARNING] [_prov_engine_client.py::68] {'SERVERLESS_RUNTIME': {'NAME': 'Example Serverless Runtime', 'FAAS': {'CPU': 1, 'MEMORY': 768, 'DISK_SIZE': 3072, 'FLAVOUR': 'Nature', 'ENDPOINT': ''}, 'SCHEDULING': {'POLICY': 'ENERGY'}, 'DEVICE_INFO': {'LATENCY_TO_PE': 0.666, 'GEOGRAPHIC_LOCATION': 'Atlantide'}}}
[2024-02-26 10:21:19,013] [WARNING] [_prov_engine_client.py::70] Create [POST] URL: http://cognit-lab.sovereignedge.eu:1337/serverless-runtimes
[2024-02-26 10:21:21,121] [WARNING] [_prov_engine_client.py::166] Retrieve [GET] URL: http://cognit-lab.sovereignedge.eu:1337/serverless-runtimes/2505
...
COGNIT Serverless Runtime ready!
[2024-02-26 10:22:35,435] [WARNING] [_serverless_runtime_client.py::48] Faas execute sync [POST] URL: http://[2001:67c:22b8:1::15]:8000/v1/faas/execute-sync
[2024-02-26 10:22:35,436] [WARNING] [_serverless_runtime_client.py::49] Faas execute sync payload: lang='PY' fc='gAWV/AEAAAAAAACMF2Nsb3VkcGlja2xlLmNsb3VkcGlja2xllIwOX21ha2VfZnVuY3Rpb26Uk5QoaACMDV9idWlsdGluX3R5cGWUk5SMCENvZGVUeXBllIWUUpQoSwBLAEsASwFLAktDQw5kAWQAbAB9AHwAagFTAJROSwCGlIwGcGFuZGFzlIwLX192ZXJzaW9uX1+UhpRoCoWUjEwvaG9tZS9hYnJvc2EvcmVwb3MvZ2l0aHViLWRldmljZS1ydW50aW1lLXB5L2V4YW1wbGVzL21pbmltYWxfb2ZmbG9hZF9zeW5jLnB5lIwLcGFuZGFzX2Z1bmOUSx1DBAgBBgGUKSl0lFKUfZROTk50lFKUjBxjbG91ZHBpY2tsZS5jbG91ZHBpY2tsZV9mYXN0lIwSX2Z1bmN0aW9uX3NldHN0YXRllJOUaBV9lH2UKIwIX19uYW1lX1+UaA+MDF9fcXVhbG5hbWVfX5RoD4wPX19hbm5vdGF0aW9uc19flH2UjA5fX2t3ZGVmYXVsdHNfX5ROjAxfX2RlZmF1bHRzX1+UTowKX19tb2R1bGVfX5SMCF9fbWFpbl9flIwHX19kb2NfX5ROjAtfX2Nsb3N1cmVfX5ROjBdfY2xvdWRwaWNrbGVfc3VibW9kdWxlc5RdlIwLX19nbG9iYWxzX1+UfZR1hpSGUjAu' fc_hash='69eb74d492613f0002d615e4e6a9f29579a7f882766cc8b8d8c139f0c3e76094' params=[]
Offloaded function result ret_code=<ExecReturnCode.SUCCESS: 0> res='2.2.1' err=None
COGNIT Serverless Runtime deleted!
- Note that 'res' value shows the version of the third party library installed, as this is the value we are returning in the 'pandas_func' we offloaded to the SR.