Skip to content

Deploying the FastAPI YOLOv5

Deploying to AWS

There are two models available for the bio project: a specific cteno model and a general YOLOv5 model. These are deployed in AWS using the CDK. The deployment script will create a new stack in the bio account with the FastAPI YOLOv5 API to the us-west-2 region.

The example below is just for the cteno model. The general YOLOv5 model is deployed in the same way.

Prerequisites

  • The cteno model is available as a models.pt file with an associated names.txt file.
  • A solid network connection to AWS - loosing a connection while a CDK stack is being deployed can result in hung state - not easy to recover from.
  • AWS credentials set for the bio account

Login to the machine doris.shore.mbari.org as the user mldevops and set the AWS keys for the bio account.

export AWS_ACCESS_KEY_ID=<your-access-key for the bio account>
export AWS_SECRET_ACCESS_KEY=<your-secret-key for the bio account>

Run the deployment script to deploy the FastAPI YOLOv5 stack to AWS.
This script will create a new stack in the bio account with the FastAPI YOLOv5 model.
The stack will be deployed in the us-west-2 region.

cd /data/901103-bio
deploy_y5x6_fastapi_aws.sh

After the script completes, you should see something like the following. Note the name of the URL that is output. This is the URL that you will use to access the FastAPI server.

FastAPIYOeLOv5Stack FastAPIYOLOVv5ECSClusterCE6FB288 FastAPIYOLOVv5ECSServiceE3E3E3E3 FastAPIYOLOVv5ECSServiceE3E3E3E3/Service

Deploying locally

A local test can be run by running the following command:

cd /data/901103-bio
deploy_y5x6_fastapi_local.sh

Debugging

All state is stored in the log output including any running processes. If a deployed is interrupted, it can be in a state of limbo. To recover, you may need to delete the stack and start over. This can be done by running the following command:

If the stack is a failed state, you may see something like the following

The stack named FastAPIYOLOv5Stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Resource of type 'AWS::ECS::Cluster' with identifier 'FastAPIYOLOv5Stack-FastAPIYOLOVv5ECSClusterCE6FB288-98kJnEtQEeJ3' was not found." (RequestToken: 4946155f-6535-c775-e9e4-7608b7944923, HandlerErrorCode: NotFound)

In that case, you need to go into the AWS console and clean the stack by hand in the CloudFormation console. Then, you can run the command again to deploy the stack.

Otherwise, simply make changes as needed to the configuration yaml file, and re-run the deploy command.


**Updated: 2024-10-25 **