Example | cortex
Example
# main.py
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Data(BaseModel):
msg: str
@app.post("/")
def handle_async(data: Data):
return dataFROM 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:appConfigure a Cortex deployment
Create a Cortex deployment
Wait for the API to be ready
docker build . -t hello-worlddocker run -p 8080:8080 hello-worldcurl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' localhost:8080aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.comaws ecr create-repository --repository-name hello-worlddocker tag hello-world <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-worlddocker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-world# cortex.yaml
- name: hello-world
kind: AsyncAPI
pod:
containers:
- name: api
image: <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-worldcurl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' http://***.amazonaws.com/hello-worldcurl http://***.amazonaws.com/hello-world/<REQUEST_ID>