Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Using Wildcard Subdomains with API Gateway #1355

Open atkallie opened 6 years ago

atkallie commented 6 years ago

Context

I have developed a Django project that makes use of the django-hosts library and now I am trying to deploy it. After working through the Zappa tutorials, I became convinced that Zappa was the way to go. However, I later realized that API Gateway does not support wildcard subdomains. While this is not strictly a Zappa issue, I was wondering if there was anyone who had any success in circumventing this issue since it doesn't look like the API Gateway developers have any intention of enabling this in the near future.

Expected Behavior

Allow *.example.com to host a Django project and let Django map to a view based on the subdomain.

Actual Behavior

Wildcard subdomains are not permitted by API Gateway; only subdomains that are explicitly defined are passed.

Possible Fix

I tried to manually create a CloudFront distribution that allows "*.example.com" as a CNAME and set the raw API gateway URL as the origin. However, due to CloudFront's default caching behavior, the problem then becomes that any subdomain (e.g. api.example.com) returns a 301 redirect to the raw API Gateway URL. Not sure how the hidden CloudFront distribution created via the Custom Domains tab in API Gateway handles this.

Steps to Reproduce (for possible fix)

ptrhck commented 5 years ago

Is there any progress on this or did someone find a solution?