A “hello world” deployment
For this tutorial, assume you have a simple Flask service: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 arequirements.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 calledconfig.yaml:
Deploying your service
With the service code and dependencies ready, deploy the service:Understanding the deploy command
Full breakdown of the deploy command and config file
Full breakdown of the deploy command and config file
Command options:
app deploydeploys a new deployment or updates an existing one.--config-filedefines the location of the config file that contains the configuration for your deployment.
nameis the globally unique identifier of your deployment. No two deployments can have the same name.portis 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.typetakes 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.
commandsis 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 havemetaflow in your environment already, use the following snippet to generate the headers for your call:
metaflow installed, use the lightweight ob-auth package instead:
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-authwith an IAM machine user, install it withpip install ob-auth[aws].
Up next
- For a deeper understanding of working with deployments, see Deployments deep dive.
- To manage deployments from the command line, see the Deployments CLI reference.