IBM Code Engine allows you to run your application, job or container on a managed serverless platform. Auto-scale workloads and only pay for the resources you consume.
- Install IBM Cloud backend dependencies:
python3 -m pip install lithops[ibm]-
If you don't have an IAM API key created, navigate to the IBM IAM dashboard.
-
Click
Create an IBM Cloud API Keyand provide the necessary information. -
Copy the generated IAM API key (you can only see the key the first time you create it, so make sure to copy it).
-
Navigate to the resource groups dashboard, and copy the desired resource group ID.
-
Edit your Lithops config and add the following keys:
lithops: backend: code_engine ibm: iam_api_key: <IAM_API_KEY> region: <REGION> resource_group_id: <RESOURCE_GROUP_ID>
| Group | Key | Default | Mandatory | Additional info |
|---|---|---|---|---|
| ibm | iam_api_key | yes | IBM Cloud IAM API key to authenticate against IBM services. Obtain the key here | |
| ibm | region | yes | IBM Region. One of: eu-gb, eu-de, eu-es, us-south, us-east, br-sao, ca-tor, jp-tok, jp-osa, au-syd |
|
| ibm | resource_group_id | yes | Resource group id from your IBM Cloud account. Get it from here. Required to auto-create a Code Engine project |
| Group | Key | Default | Mandatory | Additional info |
|---|---|---|---|---|
| code_engine | project_name | no | Name of an existing Code Engine project. If not provided, Lithops creates lithops-<region>-<user_key> automatically |
|
| code_engine | region | no | Code Engine region. One of: eu-gb, eu-de, eu-es, us-south, us-east, br-sao, ca-tor, jp-tok, jp-osa, au-syd. Lithops uses the region set under the ibm section if not set here |
|
| code_engine | docker_server | docker.io | no | Container registry URL |
| code_engine | docker_user | no | Container registry user name | |
| code_engine | docker_password | no | Container registry password/token. For Docker Hub, log in to your Docker Hub account and generate a new access token here | |
| code_engine | max_workers | 1000 | no | Max number of workers per FunctionExecutor() |
| code_engine | worker_processes | 1 | no | Number of Lithops processes within a given worker. This can be used to parallelize function activations within a worker. It is recommended to set this value to the same number of CPUs as the container. |
| code_engine | runtime | no | Docker image name. | |
| code_engine | runtime_cpu | 0.125 | no | CPU limit. Default 0.125 vCPU. See valid combinations |
| code_engine | runtime_memory | 256 | no | Memory limit in MB. Default 256 MB. See valid combinations |
| code_engine | runtime_timeout | 600 | no | Runtime timeout in seconds. Default 600 seconds |
| code_engine | connection_retries | no | If specified, number of API call retries in case of connection failure with error code 500 |
If a pre-built runtime is not provided, Lithops will automatically build the default runtime the first time you run a script. For this task it uses the Docker command installed locally on your machine. To make this work, you need to:
-
Login to your container registry account:
docker login
If you need to create a runtime with custom system packages and libraries, please follow Building and managing Lithops runtimes to run the functions
To configure Lithops to access a private repository in your Docker Hub account, you need to extend the Code Engine config and add the following keys:
code_engine:
....
docker_server : docker.io
docker_user : <container registry username>
docker_password : <container registry access TOKEN>To configure Lithops to access to a private repository in your IBM Container Registry, you need to extend the Code Engine config and add the following keys:
code_engine:
....
docker_server : us.icr.io # Change-me if you have the CR in another region
docker_user : iamapikey
docker_password : <IBM IAM API KEY>
docker_namespace : <namespace> # namespace name from https://cloud.ibm.com/registry/namespacesOnce you have your compute and storage backends configured, you can run a Hello World function with:
lithops hello -b code_engine -s ibm_cosYou can view the function executions logs in your local machine using the lithops client:
lithops logs pollDelete Lithops runtimes, job runs, and cached metadata:
lithops clean -b code_engine -s ibm_cosTo also delete the Code Engine project and local cache:
lithops clean -b code_engine -s ibm_cos --all