I am deploying a fast API app behind AWS ALB, with listener rule path pattern /api/v1/ points towards fast API. My app looks like this
from typing import Union
import os
import mysql.connector
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
print("Root path hit")
return {"App": "Fargate"}
@app.get("/api/v1/")
def read_apiv1():
print("Root path hit")
return {"App": "Path Fargate API v1"}
I deployed the app in ECS using docker and my docker run command is
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80", "--root-path", "/api/v1"]
Now when I hit my AWS ALB dns suffixed with /api/v1/ I see the endpoint /api/v1 which throws the response {"App": "Path Fargate API v1"}. However, based on the documentation from fast API it should load the api endpoint with /.
Can anyone help me why I am getting this unexpected behavior? Do I have to manually write /api/v1 before all of my endpoints?