API gateway not working with custom domain

0

Hello, I am trying to use API gateway with a lambda function, but with my own domain (which is on route 53). This is my current config: in API gateway I created a resource with a GET method, and I published it to a stage I called v1. I get an endpoint like

https://11111111.execute-api.us-east-1.amazonaws.com/v1

if I call this endpoint I can see the reply from my lambda function. so far so good. Then In API gateway again, I made a custom domain name for api.mydomain.com, and I get something like

22222222.execute-api.us-east-1.amazonaws.com

finally in route 53 I created a record type A (api.mydomain.com), marked as ALIAS and with value

22222222.execute-api.us-east-1.amazonaws.com

If I try to call https://api.mydomain.com/v1 I get a 403 error.

Am I missing something?

Also, do I need to enable CORS to allow any browser to call this endpoint?

3 Answers
0

Thank you for the detailed description. To proceed, check the x-amzn-errortype header in the 403 error and refer to this article for the resolution.


Based on the description, it's likely that the 403 is due to the domain URL includes the stage while stage (v1 in the provided example) is not necessary.

AWS
weidi
answered a year ago
0

Hello, the x-amzn-errortype value is "ForbiddenException". I can see several use cases for that in the page you indicated. I also tried to call my endpoint without the stage but I got the same error. I'd need stages anyway as I want to be able to test my API on another stage.

thank you

answered a year ago
0

The 403 error is due to the domain URL includes the stage v1 while invoking the API. After creating custom domain you must map the API with its stage name. As you map the API stage name with the custom domain you do not need to add the stage name along with the custom domain while invoking the API.

While mapping the API to custom domain, there is an optional column for adding base path mapping. For your use-case, you can add your stage name v1 in the base path mapping as well. Thus, you will be able to invoke your API as follows: https://api.mydomain.com/v1

AWS
SUPPORT ENGINEER
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions