This repo trains a Machine Learning model and deploys it on AWS. The end result is a fully serverless prediction service that users or applications can connect to.
.
├── code
│ ├── lambda-function
│ │ └── lambda_function.py
│ ├── fit-model.py # ─┐
│ └── fit-model.ipynb # ─┴─ These files do the same thing. Run your favorite.
├── requirements.txt
└── README.md
- Create a virtual environment using
venv
and activate it; - Install dependencies (
$ pip install -r requirements.txt
); - Run either one of the
fit-model
files. This will export the model in./code/lambda-function/
;fit-model.py
fit-model.ipynb
(has more context but requires ipykernel)
- Compress the
lambda-function/
directory; - Create an AWS Lambda function;
- Create Lambda Layers
for
joblib
,numpy
,scipy
andthreadpoolctl
(read article for more info details on how to do this) and add them to your function; - Create a public Lambda Function URL; and
- Start posting requests!
Example with curl
:
curl -X POST \
'<your-function-url-here> \
-H 'Content-Type: application/json' \
-d '{"meanConcavePoints": 0.07951, "worstRadius": 24.86, "worstTexture": 26.58, "worstArea": 1866.0, "worstConcavePoints": 0.1789}'
Example with Insomnia: