I have deployed a simple fast api to aws API gateway .All the end points working fine however i am unable to load the swagger docs page I see below error
Api Code:
from fastapi import FastAPI
from mangum import Mangum
import os
from fastapi.middleware.cors import CORSMiddleware
stage = os.environ.get('STAGE', None)
openapi_prefix = f"/{stage}" if stage else "/"
app = FastAPI(title="MyAwesomeApp",root_path="stage")
@app.get("/")
def get_root():
return {"message": "FastAPI running in a Lambda function"}
@app.get("/info")
def get_root():
return {"message": "TestInfo"}
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
handler = Mangum(app)
I tried adding the root as mentioned below https://fastapi.tiangolo.com/advanced/behind-a-proxy/ Any help on this will be appreciated .
I found the solution we need to add root_path="/dev"
like app = FastAPI(title=settings.NAME,root_path="/dev")
while creating fast api app .This root path should be same as the api gatway stage name .
However this approach does not work if you are using fastapi versioning