Zappa icon indicating copy to clipboard operation
Zappa copied to clipboard

Issue: API Gateway v2 events cause double path prefix in WSGI routing

Open 0xrohitgarg opened this issue 1 year ago • 1 comments

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
  • rawPath in event: /dev/collection (includes stage)
  • script_name set 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

  1. replace() doesn't modify the original string
  2. Checks if script_name is 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.

0xrohitgarg avatar Sep 17 '25 05:09 0xrohitgarg

Fixed/Released

https://github.com/zappa/Zappa/releases/tag/0.61.0

closing

monkut avatar Nov 22 '25 01:11 monkut