Website
Slack
Search…
0.42
Get started
Overview
Clusters
Management
Instances
Observability
Networking
Advanced
Workloads
Realtime
Example
Configuration
Containers
Autoscaling
Traffic Splitter
Metrics
Statuses
Troubleshooting
Async
Batch
Task
Clients
Install
Uninstall
CLI commands
Python client
Powered By
GitBook
Example
Define an API
# main.py
​
from
fastapi
import
FastAPI
from
pydantic
import
BaseModel
​
app
=
FastAPI
()
​
class
Data
(
BaseModel
):
msg
:
str
​
@app
.
post
(
"/"
)
def
handle_post
(
data
:
Data
):
return
data
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
docker
build
.
-t hello-world
Run a container locally
docker
run -p
8080
:8080 hello-world
Make a request
curl
-X POST -H
"Content-Type: application/json"
-d
'{"msg": "hello world"}'
localhost:8080
Login 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.com
Create a repository
aws ecr create-repository --repository-name hello-world
Tag the image
docker
tag hello-world
<
AWS_ACCOUNT_ID
>
.dkr.ecr.us-east-1.amazonaws.com/hello-world
Push the image
docker
push
<
AWS_ACCOUNT_ID
>
.dkr.ecr.us-east-1.amazonaws.com/hello-world
Configure a Cortex deployment
# cortex.yaml
​
-
name
:
hello
-
world
kind
:
RealtimeAPI
pod
:
containers
:
-
name
:
api
image
:
<AWS_ACCOUNT_ID
>
.dkr.ecr.us
-
east
-
1.amazonaws.com/hello
-
world
Create a Cortex deployment
cortex deploy
Wait for the API to be ready
cortex get --watch
Get the API endpoint
cortex get hello-world
Make a request
curl
-X POST -H
"Content-Type: application/json"
-d
'{"msg": "hello world"}'
http://***.amazonaws.com/hello-world
Workloads - Previous
Realtime
Next
Configuration
Last modified
7mo ago
Copy link
Outline
Define an API
Create a Dockerfile
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
Wait for the API to be ready
Get the API endpoint
Make a request