Question:
I am aware that many similar questions have been posted and answered here but none of them is quite the same with what I am experiencing.
I have a Lambda function that handles incoming requests (GET and POST). I also set up an api gateway as public facing endpoint. Additionally, I set up custom domain following Set up Custom Domain Name for API Host Name
The testing call works in both of lambda and api gateway console. Everything also works using the invoke URL but not with the custom domain I’ve set up.
Here are some more details:
Invoke URL (Works) :
1 2 |
https://{api gateway id}.execute-api.us-west-2.amazonaws.com/prod/endpoint |
Custom domain endpint (Doesn’t work):
1 2 |
https://api.{my domain}.com/endpoint |
Base Path Mapping:
1 2 |
/endpoint endpoint:prod |
All Method Auth:
1 2 3 |
Authorization None API Key Not required |
Route53:
1 2 |
A record as alias that points api.{my domain}.com to the cloudfront distribution domain name as alias target. |
I’d really appreciate if anyone knows what’s going out here.
Answer:
I had met the same question several years ago and solved it by removing the ‘stage’ name from the URL.
- the URL of gateway API seems like the following:
1 2 |
https://{id}.execute-api.{region}.amazonaws.com/{stage}/todos |
- if you have routed a custom domain
https://api.xxx.com
to gateway API{apiName}:{stage}
, it seems like the following:
1 2 3 4 5 |
https://api.xxx.com path: / target: {apiName}:{stage} |
- Finally, the correct way to call it is to remove the stage name:
1 2 3 4 5 6 7 8 |
// **remove stage name!!!!** // Right https://api.xxx.com/todos // Wrong https://api.xxx.com/{stage}/todos |