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.
To build the Docker image, run the following command with the Deployment
folder as the current directory:
docker build -t penguin-app .
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
Steps to deploy a container on AWS ECS:
-
Create a repository in ECR through the AWS console.
-
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. -
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
-
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]
-
Push the tagged container to the AWS ECR Repository:
docker push [AWS ACCOUNT ID].dkr.ecr.[REGION].amazonaws.com/[REPO NAME]:[USER-DEFINED TAG]
-
Create an ECS cluster through the AWS console.
-
Make sure that the security group in front of the cluster instances has specific rules allowing inbound and outbound traffic through TCP port 80.
-
Create an ECS Task through the AWS console using the desired image in the ECR repository.
-
Run the ECS Task.
-
Take note of the Public IP of the instance where the container was deployed and send requests to it.