This folder contains the code and supporting files needed to create a serverless model API. It includes the following files and folders:
api/app.py
- Code for the application's Lambda function.api/Dockerfile
- The Dockerfile to build the container image for local testing.api/requirements.txt
- The pip requirements installed in the test container.
Requirements:
Create and start the API as a local docker container using docker-compose
:
docker compose build lambda
docker compose -f docker-compose.yml -f docker-compose.override.yml up -d lambda
Testing with curl
:
curl -POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"text": "A test sentence."}'
Testing with python
and requests
:
import json
import requests
url = "http://localhost:9000/2015-03-31/functions/function/invocations"
headers = {"Content-Type": "application/json"}
payload = json.dumps({"text": 'A test sentence.'})
response = requests.post(url, data=payload, headers=headers)
Testing running the code in the services/jupyter/src/notebooks/query_model_api.ipynb
notebook.
Requirements:
- Docker
- An AWS Account
- AWS CLI installed and configured
- a
.env
file in the root of this project (based on.env.sample
). Set theAWS_ACCOUNT_ID
andAWS_REGION
variables in this file.
- Create a docker image and push to the ECR repository:
make deploy_to_aws_ecr
- Create a IAM role for the Lambda function:
make create_lambda_role
- Create the Lambda function:
make create_lambda_function
If you want to contribute to this service you should:
- Update one or more of the following files (based on how you want to change the API):
api/app.py
: the logic of the API, thelambda_handler
function is the entrypoint for the AWS Lambda functionapi/requirements.txt
: the python requirements of the appapi/Dockerfile
: in case you want to change external dependency or the build of the image
- Create and test API locally as described in 'Create API locally in a Docker container'