Skip to content

CLI Starter Tutorial

This starter tutorial is from the command line using the UbiOps CLI.

Requirements

Preparation

In your favorite terminal program run the following command to install the UbiOps CLI.

pip install ubiops-cli

Now login to UbiOps using the CLI and set your default project.

ubiops signin

ubiops current_project set PROJECT_NAME

For PROJECT_NAME use your own project. You can find your project name in the UbiOps webapp or with the following command.

ubiops projects list

Then download a prepared deployment. Please, use the link to download it.

Create a deployment

The next step is to create the structure of the prepared deployment in your project. The deployment parameters can be specified using a yaml file. Use either the echo shell command below to create the yaml file, or save the content in the yaml tab below in a file named example_deployment.yaml.

echo "deployment_name: example
deployment_description: UbiOps CLI tutorial.
input_type: structured
input_fields:
  - name: input
    data_type: double
output_type: structured
output_fields:
  - name: output
    data_type: double" > example_deployment.yaml
(echo deployment_name: example & echo deployment_description: UbiOps CLI tutorial. & echo input_type: structured & echo input_fields: & echo   - name: input & echo     data_type: double & echo output_type: structured & echo output_fields: & echo   - name: output & echo    data_type: double) > example_deployment.yaml
deployment_name: example
deployment_description: UbiOps CLI tutorial.
input_type: structured
input_fields:
  - name: input
    data_type: double
output_type: structured
output_fields:
  - name: output
    data_type: double

Create the deployment:

ubiops deployments create -f example_deployment.yaml

Duplicating deployments

If you want to overwrite the deployment name in the yaml file upon deployment creation, you can easily do so by adding a deployment name (.e.g example-duplicate) as argument. This is especially useful if you want to duplicate a deployment: ubiops deployments create -f example_deployment.yaml example-duplicate

Deploy your code

The next step is to deploy the code. The downloaded zip should be unzipped first, as the command expects a directory instead of a zip. After unzipping example_deployment_package.zip, the code directory can be found as deployment_package or example_deployment_package/deployment_package, depending on how you unzip. The root of this code directory contains a deployment.py which is used by UbiOps as entry point of your code. See the Deployment package structure page for more information about the structure of the deployment package.

Use the echo shell command below or copy the content of the second tab in a yaml file called example_deployment_version.yaml. Since all keys in the two yaml files (deployment creation and version deployment) are unique, you could also define them in the same file and use that for both deployment creation and version deployment. It is possible to create 1 or more versions of a deployment. Each version has the same input and output, but the deployed code package, base environment, instance_type and other settings can be different. In this example, we are building the first version of the deployment. For more information about deployment versions, see our Deployments versions page.

echo "version_name: v1
deployment_name: example
environment: python3-7
instance_type: 256mb
minimum_instances: 0
maximum_instances: 1
maximum_idle_time: 1800
request_retention_mode: full
request_retention_time: 3600" > example_deployment_version.yaml
(echo version_name: v1 & echo deployment_name: example & echo environment: python3-7 & echo instance_type: 256mb & echo minimum_instances: 0 & echo maximum_instances: 1 & echo maximum_idle_time: 1800 & echo request_retention_mode: full & echo request_retention_time: 3600) > example_deployment_version.yaml
version_name: v1
deployment_name: example
environment: python3-7
instance_type: 256mb
minimum_instances: 0
maximum_instances: 1
maximum_idle_time: 1800
request_retention_mode: full
request_retention_time: 3600

Deploy the code in deployment_package (or example_deployment_package/deployment_package) to a new deployment version v2 of deployment example:

ubiops deployments deploy example -v v2 -dir deployment_package/ -f example_deployment_version.yaml

See if it worked

Now see if it works by listing all deployed versions of the example deployment:

ubiops deployment_versions list -d example
When your deployment version is available we can create requests. Ofcourse you can also use the UI to see if everything worked.

Create a requests

The example deployment in this starter tutorial multiplies the input float input by a random number and returns it as output. To create a request input=100 to version v1 (or use version v2), use:

ubiops deployments requests create example -v v1 --data \"{\"input\": 100}\"
When the request finishes, you will see the output of the deployment.

Clean up

You can delete version v1 (or version v2) of deployment example using:

ubiops deployment_versions delete v1 -d example
You will be prompted for confirmation. Press 'y' to confirm. You could also add the -y option.

You can delete the whole deployment (and all its versions) using:

ubiops deployments delete example
You will be prompted for confirmation. Press 'y' to confirm. You could also add the -y option.

What's next?

After you are done building your first deployment, you can check out the tutorials page to see how you can combine UbiOps together with popular data science packages, or integration with other cloud provider tools.