Example

Define an API

# main.py

from fastapi import FastAPI
from typing import List

app = FastAPI()

@app.post("/")
def handle_batch(batch: List[int]):
    print(batch)

@app.post("/on-job-complete")
def on_job_complete():
    print("done")

Create a Dockerfile

FROM python:3.8-slim

RUN pip install --no-cache-dir fastapi uvicorn

COPY main.py /

CMD uvicorn --host 0.0.0.0 --port 8080 main:app

Build an image

Run a container locally

Make a request

Login to ECR

Create a repository

Tag the image

Push the image

Configure a Cortex deployment

Create a Cortex deployment

Get the API endpoint

Make a request

View the logs

Last updated