This is a machine learning service template that contains the sample code of a scikit-learn machine learning model. The model is
- served using FastAPI,
- containerized using Docker, and
- deployed to Amazon Web Services (AWS) using Terraform.
To enable data scientists and ML practitioner to focus on building machine learning models in production and not worry about model serving or model deployment.
- Serve machine learning models with FastAPI by Andrea D'Agostino
- Deploy a FastAPI App on AWS ECS by Tom Sharp
-
Clone this repository:
$ git clone [email protected]:shilongjaycui/ml-service-template.git
-
Navigate into the repository:
$ cd ml-service-template
-
Train a machine learning model:
$ cd app && make train && cd ..
-
Create an AWS account if you don't have one already.
-
Install AWS Command Line Interface (CLI); then, verify you have AWS CLI successfully installed on your local machine by running the following commands:
$ which aws /usr/local/bin/aws $ aws --version aws-cli/2.15.30 Python/3.11.6 Darwin/23.3.0 botocore/2.4.5
-
Create an IAM user with just enough permissions (see why here) to deploy Docker containers to ECS:
-
Configure the terminal session to use the newly-created IAM user:
$ aws configure AWS Access Key ID: <paste your access key ID from the previous step and hit enter> AWS Secret Access Key: <paste your secret access key from the previous step and hit enter> Default region name: us-west-2 Default output format [None]: <just hit enter>
-
Install Terraform by following the instructions here.
-
Set up Amazon Elastic Container Registry (Amazon ECR) in your AWS account:
$ make setup-ecr
-
Build and push your Docker image to Amazon ECR:
$ make deploy-container
-
Deploy your machine learning service (served & containerized scikit-learn model) to AWS:
$ make deploy-service
-
Click on the link (Terraform output) in your terminal to interact with your machine learning service.
-
IMPORTANT: When you're done interacting with your service, destroy it.
$ make destroy-service
- library-agnostic development: You can develop your machine learning model using scikit-learn, PyTorch, TensorFlow, or Keras.
- cloud-agnostic deployment: You can deploy your machine learning model to AWS, Azure, or GCP.