Here are the steps to deploy your MLflow model to SageMaker:
-
Preparation:
- Make sure you have the following tools installed:
- Set up your AWS account and permissions correctly. Youโll need an IAM role with permissions to create a SageMaker endpoint, access an S3 bucket, and use the Elastic Container Registry (ECR). This role should also be assumable by the user performing the deployment.
-
Create an MLflow Model:
- Before deploying, ensure you have an MLflow Model. If you donโt have one, you can create a sample scikit-learn model by following the MLflow Tracking Quickstart.
- Note down the model URI, such as
runs:/<run_id>/<artifact_path>
(or models:/<model_name>/<model_version>
if you registered the model in the MLflow Model Registry).
-
Test Your Model Locally:
- Itโs recommended to test your model locally before deploying it to a production environment.
-
Deploy the Model to SageMaker Endpoint:
-
Access the SageMaker Endpoint:
- The SageMaker endpoint provides REST endpoints for inference. For example, the
/invocations
endpoint accepts CSV and JSON input data and returns prediction results.
Remember that MLflow supports both the general pyfunc
deployment (default) and the mleap
flavor for SageMaker deployment. If you choose the mleap
flavor, the endpoint will only accept JSON-serialized pandas DataFrames in the split orientation. You can specify this format using a Content-Type
request header value of application/json
.
For more details and Python API references, check out the MLflow documentation on deploying to SageMaker.