Skip to content

Commit

Permalink
Update examples (#2234)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2f3caa4)
  • Loading branch information
deliahu committed Jun 8, 2021
1 parent 931d67f commit f26f269
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
16 changes: 10 additions & 6 deletions docs/workloads/async/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
# main.py

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class Data(BaseModel):
msg: str

@app.post("/")
def hello_world():
return {"msg": "hello world"}
def handle_async(data: Data):
return data
```

### Create a `Dockerfile`
Expand All @@ -28,19 +32,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app
### Build an image

```bash
docker build . --tag hello-world
docker build . -t hello-world
```

### Run a container locally

```bash
docker run --port 8080:8080 hello-world
docker run -p 8080:8080 hello-world
```

### Make a request

```bash
curl --request POST --header "Content-Type: application/json" localhost:8080
curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' localhost:8080
```

### Login to ECR
Expand Down Expand Up @@ -101,7 +105,7 @@ cortex get hello-world
### Make a request

```bash
curl --request POST --header "Content-Type: application/json" http://***.amazonaws.com/hello-world
curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' http://***.amazonaws.com/hello-world
```

### Get the response
Expand Down
9 changes: 5 additions & 4 deletions docs/workloads/batch/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def on_job_complete():
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
Expand All @@ -33,19 +34,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app
### Build an image

```bash
docker build . --tag hello-world
docker build . -t hello-world
```

### Run a container locally

```bash
docker run --port 8080:8080 hello-world
docker run -p 8080:8080 hello-world
```

### Make a request

```bash
curl --request POST --header "Content-Type: application/json" --data '[1,2,3,4]' localhost:8080
curl -X POST -H "Content-Type: application/json" -d '[1,2,3,4]' localhost:8080
```

### Login to ECR
Expand Down Expand Up @@ -101,7 +102,7 @@ cortex get hello-world
### Make a request

```bash
curl --request POST --header "Content-Type: application/json" --data '{"workers": 2, "item_list": {"items": [1,2,3,4], "batch_size": 2}}' http://***.amazonaws.com/hello-world
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
```

### View the logs
Expand Down
19 changes: 12 additions & 7 deletions docs/workloads/realtime/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
# main.py

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

@app.get("/")
def hello_world():
return {"msg": "hello world"}
class Data(BaseModel):
msg: str

@app.post("/")
def handle_post(data: Data):
return data
```

### Create a `Dockerfile`
Expand All @@ -20,6 +24,7 @@ def hello_world():
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
Expand All @@ -28,19 +33,19 @@ CMD uvicorn --host 0.0.0.0 --port 8080 main:app
### Build an image

```bash
docker build . --tag hello-world
docker build . -t hello-world
```

### Run a container locally

```bash
docker run --port 8080:8080 hello-world
docker run -p 8080:8080 hello-world
```

### Make a request

```bash
curl --request POST localhost:8080
curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' localhost:8080
```

### Login to ECR
Expand Down Expand Up @@ -101,5 +106,5 @@ cortex get hello-world
### Make a request

```bash
curl --request POST http://***.amazonaws.com/hello-world
curl -X POST -H "Content-Type: application/json" -d '{"msg": "hello world"}' http://***.amazonaws.com/hello-world
```
4 changes: 2 additions & 2 deletions docs/workloads/task/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CMD exec python main.py
### Build an image

```bash
docker build . --tag hello-world
docker build . -t hello-world
```

### Run a container locally
Expand Down Expand Up @@ -83,7 +83,7 @@ cortex get hello-world
### Make a request

```bash
curl --request POST --header "Content-Type: application/json" --data '{}' http://***.amazonaws.com/hello-world
curl -X POST -H "Content-Type: application/json" -d '{}' http://***.amazonaws.com/hello-world
```

### View the logs
Expand Down

0 comments on commit f26f269

Please sign in to comment.