Example
Define an API
# main.py
print("hello world")Create a Dockerfile
DockerfileFROM python:3.8-slim
COPY main.py /
CMD exec python main.pyBuild an image
docker build . -t hello-worldRun a container locally
docker run -it --rm hello-worldLogin to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.comCreate a repository
aws ecr create-repository --repository-name hello-worldTag the image
docker tag hello-world <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-worldPush the image
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-worldConfigure a Cortex deployment
# cortex.yaml
- name: hello-world
kind: TaskAPI
pod:
containers:
- name: api
image: <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/hello-world
command: ["python", "main.py"]Create a Cortex deployment
cortex deployGet the API endpoint
cortex get hello-worldMake a request
curl -X POST -H "Content-Type: application/json" -d '{}' http://***.amazonaws.com/hello-worldView the logs
cortex logs hello-world <JOB_ID>Last updated