Skip to content

Double stage redirect when using custom domain with API Gateway V2 #1409

@SMCodesP

Description

@SMCodesP

When using API Gateway V2 with a custom domain (without Route53), Zappa causes a double stage redirect. The custom domain is already mapped to the correct stage in API Gateway's API Mappings, but Zappa still tries to redirect to the stage name, resulting in a duplicated stage path.

For example:

  • Custom domain: api.example.com
  • Stage: dev
  • API Mapping: api.example.comdev stage (path: empty)

When accessing https://api-test.maquinaweb.com.br/admin/, it redirects to https://api-test.maquinaweb.com.br/dev/admin/, which returns a "not found" error because the stage is duplicated in the path.

Image

This resulting to https://api-test.maquinaweb.com.br/dev/dev/admin/

Steps to Reproduce

  1. Deploy the application with API Gateway V2: zappa deploy dev
  2. Create a custom domain in API Gateway (without using Route53/Certificate Manager integration from Zappa)
  3. Configure API Mapping with empty path pointing to your API and stage
  4. Access any endpoint through the custom domain
  5. Observe the redirect includes the stage name, causing a double stage path

This my configuration AWS Custom Domain Names with API mappings
Image

Configuration

zappa_settings.json:

{
    "dev": {
        "aws_region": "sa-east-1",
        "django_settings": "core.settings",
        "exclude": [
            "boto3",
            "botocore",
            "s3transfer",
            "concurrent",
            ".env",
            ".venv",
            ".ruff_cache",
            ".vscode",
            "media"
        ],
        "profile_name": "myprofile",
        "project_name": "myproject",
        "architecture": "arm64",
        "runtime": "python3.11",
        "s3_bucket": "myproject-dev",
        "environment_variables": {
            "PRODUCTION": "True"
        },
        "memory_size": 1024,
        "apigateway_version": "v2",
        "base_path": ""
    }
}

Repository to replication: https://github.com/maquinaweb/test-zappa

Environment

  • Zappa version: 0.61.3
  • Python version: 3.11
  • AWS Region: sa-east-1
  • Architecture: arm64
  • API Gateway version: v2
  • Custom domain configured manually (not through Zappa)

What I've Tried

  1. Setting "base_path": "/" in zappa_settings.json - But changed not redirects but all routes is 404
  2. Ensuring API Mapping path is empty - Still redirects with stage name
  3. Disabling the default API Gateway endpoint - Still redirects

Additional Context

This issue started occurring after migrating from API Gateway V1 (REST API) to API Gateway V2 (HTTP API). With V1, the custom domain worked correctly without the double stage redirect issue.

Is there a way to disable the automatic stage redirect behavior when using a custom domain with API Gateway V2?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions