AWS API Gateway


#1

I’m having an issue with the AWS API Gateway’s custom domain feature. I have no problem doing base mappings for paths like /login and /dashboard, but if I also want to add a base mapping for the root (just blank or /), I get an error saying if I want a blank one, I can’t have any others. Is there any workaround to this?


#2

@RegNatarajan So what do you mean by mapping “blank or /”. You can map a domain like www.lol.com. Can you please explain with an example and also what are you trying to do?


#3

Sure, happy to elaborate. In the API Gateway’s custom domain area, you can set base mappings so that www.mydomain.x/this maps to the lambda function “this” and www.mydomain.x/that maps to the lambda function “that”. This is all working perfectly. My issue is that I also want something to happen when people simply go to www.mydomain.x (no further base mapping…just the root of the domain). When I add a blank base mapping, it says if I have a blank one, I can’t have any more. I want to know if there’s a workaround as obviously I’d rather have something happen when people go to www.mydomain.x.

Capture


#4

@RegNatarajan you will prolly have to do the root domain/CNAME mappings via CloudFront or Route53


#5

Thanks for that but I have already set up the domain for Cloudfront and I use Route53 to map to that Cloudfront FQDN. I actually have to do that for the other mappings to work. Setting up a second CNAME would obviously break the ones I have.


#6

This is a limitation of API Gateway Custom Domains…
You get either root mapping, or 1+ context mapping.

You “could” map your domain to a S3 bucket
Then enable Static website hosting on the bucket and config configure Redirect requests to point to an API endpoint.


#7

That’s what I was afraid of. I’m not crazy about redirecting subfolders to the API directly as the URLs will be ugly. I hope AWS addresses this but for now I’ll just use a subdomain (app.mydomain.com) and accept that I can’t have anything in /

It’s not what I wanted to hear but thanks for the confirmation.


#8

I found out how to do this so I’m answering my own original question. It is definitely possible, contrary to the posts above. You need to deploy child resources off the root of your api, and then create get/post methods in each of those child resources. This lets you assign lambda functions to / and to /xxx and /yyy and so on. This should be easier but it isn’t and at least there’s a solution.