Website
Slack
Search…
0.42
Get started
Overview
Clusters
Management
Instances
Observability
Networking
Advanced
Workloads
Realtime
Async
Batch
Example
Configuration
Containers
Jobs
Statuses
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
typing
import
List
5
​
6
app
=
FastAPI
()
7
​
8
@app
.
post
(
"/"
)
9
def
handle_batch
(
batch
:
List
[
int
]):
10
print
(
batch
)
11
​
12
@app
.
post
(
"/on-job-complete"
)
13
def
on_job_complete
():
14
print
(
"done"
)
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
'[1,2,3,4]'
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
:
BatchAPI
5
pod
:
6
containers
:
7
-
name
:
api
8
image
:
<AWS_ACCOUNT_ID
>
.dkr.ecr.us
-
east
-
1.amazonaws.com/hello
-
world
9
command
:
[
"uvicorn"
,
"--host"
,
"0.0.0.0"
,
"--port"
,
"8080"
,
"main:app"
]
Copied!
Create a Cortex deployment
1
cortex deploy
Copied!
Get the API endpoint
1
cortex get hello-world
Copied!
Make a request
1
curl
-X POST -H
"Content-Type: application/json"
-d
'{"workers": 2, "item_list": {"items": [1,2,3,4], "batch_size": 2}}'
http://***.amazonaws.com/hello-world
Copied!
View the logs
1
cortex logs hello-world
<
JOB_ID
>
Copied!
Workloads - Previous
Batch
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
Get the API endpoint
Make a request
View the logs