/penguin_classification_deployment

Educational project that creates a docekrized API that serves a Random Forest model to classify penguin species among Chinstrap, Gentoo, and Adélie according to the penguins dataset.

Primary LanguageJupyter Notebook

Deploying a Machine Learning Model for the Penguins Dataset

This educational project creates a docekrized API that serves a Random Forest model to classify penguin species among Chinstrap, Gentoo, and Adélie according to the penguins dataset.

Penguin species in the dataset

How to Build the Docker Image

To build the Docker image, run the following command with the Deployment folder as the current directory:

docker build -t penguin-app .

How to Create and Start the Docker Container

To create the Docker container from the image and start the uvicorn server, run the following command with the Deployment folder as the current directory:

docker run -p 3000:80 penguin-app

How to Deploy the Application on AWS

Steps to deploy a container on AWS ECS:

  1. Create a repository in ECR through the AWS console.

  2. Set environment variables with the AWS credentials in PowerShell or linux shell:

     (PowerShell:)
     $env:aws_access_key_id=
     $env:aws_secret_access_key=
    
     (linux/MAC shell:)
     export aws_access_key_id=
     export aws_secret_access_key=
    

    Alternatively, store this credentials in a .aws/credentials file inside your home folder as per the instructions here.

  3. Log in the CLI to ECR:

     aws ecr get-login-password --region [REGION] | docker login --username AWS --password-stdin [AWS ACCOUNT ID].dkr.ecr.[REGION].amazonaws.com
    
  4. Tag the container image with AWS ECR Repository name:

     docker tag [ORIGINAL IMAGE NAME] [AWS ACCOUNT ID].dkr.ecr.[REGION].amazonaws.com/[REPO NAME]:[USER-DEFINED TAG]
    
  5. Push the tagged container to the AWS ECR Repository:

     docker push [AWS ACCOUNT ID].dkr.ecr.[REGION].amazonaws.com/[REPO NAME]:[USER-DEFINED TAG]
    
  6. Create an ECS cluster through the AWS console.

  7. Make sure that the security group in front of the cluster instances has specific rules allowing inbound and outbound traffic through TCP port 80.

  8. Create an ECS Task through the AWS console using the desired image in the ECR repository.

  9. Run the ECS Task.

  10. Take note of the Public IP of the instance where the container was deployed and send requests to it.