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
1
# main.py
2
​
3
from
fastapi
import
FastAPI
4
from
pydantic
import
BaseModel
5
​
6
app
=
FastAPI
()
7
​
8
class
Data
(
BaseModel
):
9
msg
:
str
10
​
11
@app
.
post
(
"/"
)
12
def
handle_post
(
data
:
Data
):
13
return
data
Copied!
Create a
Dockerfile
1
FROM python:3.8-slim
2
​
3
RUN pip install --no-cache-dir fastapi uvicorn
4
​
5
COPY main.py /
6
​
7
CMD uvicorn --host 0.0.0.0 --port 8080 main:app
Copied!
Build an image
1
docker
build
.
-t hello-world
Copied!
Run a container locally
1
docker
run -p
8080
:8080 hello-world
Copied!
Make a request
1
curl
-X POST -H
"Content-Type: application/json"
-d
'{"msg": "hello world"}'
localhost:8080
Copied!
Login to ECR
1
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
Copied!
Create a repository
1
aws ecr create-repository --repository-name hello-world
Copied!
Tag the image
1
docker
tag hello-world
<
AWS_ACCOUNT_ID
>
.dkr.ecr.us-east-1.amazonaws.com/hello-world
Copied!
Push the image
1
docker
push
<
AWS_ACCOUNT_ID
>
.dkr.ecr.us-east-1.amazonaws.com/hello-world
Copied!
Configure a Cortex deployment
1
# cortex.yaml
2
​
3
-
name
:
hello
-
world
4
kind
:
RealtimeAPI
5
pod
:
6
containers
:
7
-
name
:
api
8
image
:
<AWS_ACCOUNT_ID
>
.dkr.ecr.us
-
east
-
1.amazonaws.com/hello
-
world
Copied!
Create a Cortex deployment
1
cortex deploy
Copied!
Wait for the API to be ready
1
cortex get --watch
Copied!
Get the API endpoint
1
cortex get hello-world
Copied!
Make a request
1
curl
-X POST -H
"Content-Type: application/json"
-d
'{"msg": "hello world"}'
http://***.amazonaws.com/hello-world
Copied!
Workloads - Previous
Realtime
Next
Configuration
Last modified
4mo ago
Copy link
Contents
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