Skip to main content
This tutorial walks you through deploying a long-running service on Anaconda Platform: a minimal Flask app packaged with its dependencies, configured with a YAML file, and launched with the CLI. To deploy a model from the model catalog instead, see Deploy a model from the model catalog.

A “hello world” deployment

For this tutorial, assume you have a simple Flask service:
The code for first-service.py:

Managing requirements

The platform automatically packages your dependencies into a Docker container to run your deployment, just like Metaflow tasks. You can declare dependencies in a few different formats. One of the easiest is a requirements.txt file at the root of your project. For all the ways to manage dependencies, see Dependency management. For this example, create a requirements.txt that specifies the one dependency, flask:

Defining a config file

You can configure the behavior of your deployment either by passing options to the CLI or by creating a config file. Anaconda recommends defining as much configuration as possible in the config file, and using CLI options occasionally to override the config file or for rapid prototyping. Create a config file called config.yaml:
Place it in the root of your project:

Deploying your service

With the service code and dependencies ready, deploy the service:
The command packages your code, builds a container image with your dependencies, provisions the workers, and exposes the service. The output ends with the URL of your deployed endpoint:

Understanding the deploy command

Command options:
  • app deploy deploys a new deployment or updates an existing one.
  • --config-file defines the location of the config file that contains the configuration for your deployment.
Config file fields:
  • name is the globally unique identifier of your deployment. No two deployments can have the same name.
  • port is the port number where your service listens. In the Flask example above, the server starts on port 8000, so the config passes the same port.
  • auth.type takes two values:
    • API: token-based authentication for programmatic clients such as cURL or Python scripts. See Accessing your deployed endpoint for an example.
    • Browser: the endpoint uses the same SSO authentication as the platform. Anyone signed in to the platform can access it.
  • commands is the command used to launch your service: the same command you would use to run the service locally. In this example, python first-service.py. You can provide multiple commands if needed.

Accessing your deployed endpoint

You can construct a request for your endpoint with cURL, Python, or the language of your choice. The only additional requirement is attaching auth headers to your request so the platform can authenticate it. If you have metaflow in your environment already, use the following snippet to generate the headers for your call:
If you are calling the endpoint from an external environment that does not have metaflow installed, use the lightweight ob-auth package instead:
Use either function to call your deployed endpoint, replacing the URL with the URL of your deployment:
The get_auth_headers() function works in all of the following cases:
  • Running locally from a script when you have a Metaflow config.
  • Running from inside a local or remote Metaflow task.
  • Running from any environment where you have a machine user configured. If you use ob-auth with an IAM machine user, install it with pip install ob-auth[aws].

Up next