Zappa
Zappa copied to clipboard
Issue: API Gateway v2 events cause double path prefix in WSGI routing
Problem
When using API Gateway v2 events with a stage (e.g., dev), requests to {apigatewayurl}/{stage}/collection result in incorrect routing.
What happens
- Request:
https://api.execute-api.us-east-1.amazonaws.com/dev/collection rawPathin event:/dev/collection(includes stage)script_nameset to:/dev- Final route becomes:
/dev/dev/collection❌
Expected behavior
- Final route should be:
/dev/collection✅
Root cause
The create_wsgi_request function in zappa/wsgi.py doesn't properly strip the stage from rawPath when it's included in API Gateway v2 events.
Current code (lines 125-130)
if script_name in path_info:
environ["PATH_INFO"].replace(script_name, "")
Issues
replace()doesn't modify the original string- Checks if
script_nameis anywhere in path instead of at the beginning
Impact
- Routes fail to match expected patterns
- Affects all API Gateway v2 deployments with stages
- Works fine for v1 events and custom domains
Environment
- Zappa version: latest
- API Gateway: v2 events
- Python: 3.x
Reproduction
Deploy with a stage and make requests to {gateway_url}/{stage}/your-endpoint - routes will have double stage prefix.
Fixed/Released
https://github.com/zappa/Zappa/releases/tag/0.61.0
closing