- Serve ML model using FastAPI
- Containerize ML application using Docker/ docker-compose
- Publish Docker image to ECR and deploy the application to AWS lambda using Docker
- Conduct performance test using Locust
Inference UI | Testing image |
---|---|
conda env create -f env/environment.yml
conda activate FastAPI_classifier
python3 src/main.py
docker build -f env/Dockerfile -t fastapiimage .
docker run --name fastapicontainer -p 8000:8000 fastapiimage
docker-compose -f env/docker-compose.yml up --build
- To stop Docker-compose (inside the project directory)
docker-compose -f env/docker-compose.yml down
- Create a Docker image
docker build -f env/Dockerfile_aws -t fastapiimage_aws .
- Publish image to ECR
aws ecr create-repository --repository-name {repo_name}
aws ecr get-login-password --region {region} | docker login\
--username AWS \
--password-stdin {aws_account_id}.dkr.ecr.{region}.amazonaws.com
docker tag fastapiimage_aws {repositoryUri}:{Tag}
docker push {repositoryUri}:{Tag}
- Create a lambda function using the ECR image
- Change configuration (needed for model initialization)
- timeout -> 30s
- memory -> 1024MB
- Change configuration (needed for model initialization)
- Create Lambda URL and Test the FastAPI app
- Configuration > Function URL > Create function URL > Auth type: NONE > Additional settings:CORS enabled > Save
curl -X 'POST' \
'http://127.0.0.1:8000/predict/torch_model/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"img_url": "<image_url>"}'
Inference UI can be accessed at http://127.0.0.1:8000/docs
if running locally
pytest
locust -f tests/performance_test.py
- Testing monitor UI can be accessed at
http://127.0.0.1:8089/
- If running locally, set the host to
http://127.0.0.1:8000
to test
- Pretrained MobileNet_V2 (Tensorflow)
- Pretrained AlexNet (Pytorch)