Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FastAPI Docs 403'ing when running on AWS APIGW/Lambda with Mangum

Trying to follow https://fastapi.tiangolo.com/advanced/behind-a-proxy/?h=proxy#proxy-with-a-stripped-path-prefix but keep getting 403 when I trying to access /docs or /redoc:

I get the 403 error(image attached) if I do the below:

app = FastAPI(
        servers=servers,
        root_path="/latest", # Same 403 error without the root_path or omitting it
        root_path_in_servers=True, # Same issue when setting to False or omitting it
  • /docs and /redoc works locally, just not once I push it to AWS APIGW/Lambda
  • All other paths work without issue both locally and in APIGW/Lambda
  • I am using Mangum when it's deployed to Lambda, locally I use uvicorn
  • I tried variations of no root_path and root_path_in_servers=True or False and had the same issue
  • I have an APIGW GET /docs path setup to route to the Lambda
  • I have API GW DNS set up so my DNS goes from api.example.com > API GW CloudFront URL which is mapped to my APIGW stage named /latest, then it sends to Lambda

I also reviewed this post with a similar/same issue, and tried:

docs_url='/latest/docs',
redoc_url='/latest/redoc',
openapi_url='/latest/openapi.json'

but encountered the same 403 error(image attached) or {"detail":"Not Found"}403 Error when loading /docs

like image 326
Matthew Avatar asked Jan 24 '26 12:01

Matthew


1 Answers

app = FastAPI(openapi_prefix='/dev/')

This worked for me. Here, dev is the API stage name

like image 128
Shisir Avatar answered Jan 26 '26 09:01

Shisir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!