Explore more

Figure: The serverless request-to-prediction pattern generalizes across providers and models.
- Try similar serverless services from Google Cloud and Microsoft Azure
- Deploy cats vs dogs and other Keras models with AWS Lambda
- AWS Lambda is also good for other libraries, not just Tensorflow. You can deploy Scikit-Learn and XGBoost models with it as well
Deploying with the AWS SAM CLI
Instead of assembling the container and Lambda by hand, you can use the AWS SAM CLI (getting started) to create a Lambda function as a container image:
Run
sam init, then follow the wizard: "AWS Quick Start Templates" → "Machine Learning" as the application type → your Python version → the "TensorFlow Machine Learning Inference API" template. This creates a SAM project folder with anappfolder inside.Move your deployment files (the TensorFlow Lite model,
app.py,class_indices.json) intoapp.In
app/requirements.txt, replace TensorFlow withtflite-runtime:pillow==11.1.0 requests==2.32.3 numpy==1.26.4 tflite-runtime==2.7.0Adjust
app/Dockerfileto copy the files and set the model/classes paths:FROM public.ecr.aws/lambda/python:3.9 COPY requirements.txt ./ RUN python3.9 -m pip install -r requirements.txt -t . COPY app.py ./ COPY class_indices.json ./ COPY classification_model.tflite ./ ENV MODEL_PATH ./classification_model.tflite ENV CLASSES_PATH ./class_indices.json CMD ["app.lambda_handler"]Build and test locally:
sam build --build-dir .aws-build sam local invoke -t .aws-build/template.yaml -e events/event.jsonPut the expected JSON input (e.g.
{"url": "http://bit.ly/mlbookcamp-pants"}) intoapp/events/event.json.Deploy with
sam deploy --guided— SAM creates the ECR repository and the Lambda function for you.