MLflow using AWS App Runner
This project deploys an MLflow instance with basic auth (username/password) in AWS App Runner.
Amazon ECR
Amazon Elastic Container Registry (ECR) is a fully managed container registry that makes it easy to store, manage, share, and deploy your container images and artifacts anywhere.
App Runner
AWS App Runner is a fully managed service that makes it easy for developers to quickly deploy containerized web applications and APIs, at scale and with no prior infrastructure experience required. Start with your source code or a container image.
Amazon S3
Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.
Amazon RDS
Amazon Relational Database Service (Amazon RDS) makes it easy to set up, operate, and scale a relational database in the cloud. Amazon RDS provides six familiar database engines to choose from, including Amazon Aurora, PostgreSQL, MySQL, MariaDB, Oracle Database, and SQL Server.
The environment variables below are required to deploy this project.
Variable | Description | Default |
---|---|---|
PORT | Port for the MLflow server | 80 |
MLFLOW_ARTIFACT_URI | S3 Bucket URI for MLflow's artifact store | "./mlruns" |
MLFLOW_BACKEND_URI | SQLAlchemy database uri (if provided, the other variables MLFLOW_DB_* are ignored) |
|
MLFLOW_DB_DIALECT | Database dialect (e.g. postgresql, mysql+pymysql, sqlite) | "mysql+pymysql" |
MLFLOW_DB_USERNAME | Backend store username | "mlflow" |
MLFLOW_DB_PASSWORD | Backend store password | "mlflow" |
MLFLOW_DB_HOST | Backend store host | |
MLFLOW_DB_PORT | Backend store port | 3306 |
MLFLOW_DB_DATABASE | Backend store database | "mlflow" |
MLFLOW_TRACKING_USERNAME | Username for MLflow UI and API | "mlflow" |
MLFLOW_TRACKING_PASSWORD | Password for MLflow UI and API | "mlflow" |
You can access the MLflow UI in your App Runner URL: https://XXXXXXXXX.aws-region.awsapprunner.com/
Also, you can track your experiments using MLflow API.
import os
import mlflow
os.environ["MLFLOW_TRACKING_URI"] = "https://XXXXXXXXX.aws-region.awsapprunner.com/"
os.environ["MLFLOW_EXPERIMENT_NAME"] = "amazing-experiment"
os.environ["MLFLOW_TRACKING_USERNAME"] = "user"
os.environ["MLFLOW_TRACKING_PASSWORD"] = "pass"
# AWS AK/SK are required to upload artifacts to S3 Bucket
os.environ["AWS_ACCESS_KEY_ID"] = "AWS_ACCESS_KEY"
os.environ["AWS_SECRET_ACCESS_KEY"] = "AWS_SECRET_KEY"
SEED = 1993
mlflow.start_run()
mlflow.log_param("seed", SEED)
mlflow.end_run()
In this section, we'll walk through deploying this MLflow docker image with basic authentication.
This project provides a terraform stack that can be easily used to deploy the MLflow server with basic authentication.
NOTE: This project is not intended to be used for production deployments. It is intended to be used for testing and development.
You'll need to have the following installed:
To deploy MLflow, you'll need to:
-
Create an AWS account if you don't already have one.
-
Configure AWS CLI to use your AWS account.
-
Clone the repository: github.com/DougTrajano/mlflow-server
-
Open
mlflow-server/terraform
folder.
cd mlflow-server/terraform
- Run the following command to create all the required resources:
terraform init
terraform apply -var mlflow_username="USERNAME-HERE" -var mlflow_password="PASSWORD-HERE"
- Type "yes" when prompted to continue.
This will create the following resources:
- An S3 bucket for storing MLflow artifacts.
- An IAM role and policy for the MLflow server connect to the S3 bucket.
- An RDS database instance (MySQL) for storing MLflow metadata.
- A service in App Runner to run MLflow Tracking Server.
- Change RDS Database to Aurora Serverless will reduce the cost drastically for those who don't use MLflow frequently, but Aurora Serverless can only connect with AWS resources that are in the same VPC, AWS App Runner doesn't support VPC yet.