How to attach custom domain names to an API gateway ?
November 18, 2020 / Eternal Team
What is API Gateway?
As per Amazon definition “API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.” APIs act as the “front door” for applications to access data, business logic, or functionality from your backend services. Using API Gateway, you can create RESTful APIs and WebSocket APIs that enable real-time two-way communication applications. API Gateway supports containerized and serverless workloads, as well as web applications.
How to attach custom domain names to an API gateway?
Pre-Requirements
- API gateway access
- Domain name/Subdomain name
Step 1
As you can see we have created an API-gateway which is invoked in postman and is working

Create an ACM certificate for the domain name which should be attached to the API-Gateway
Step 2
- Open ACM in AWS console and click on Request a certificate
- Select Request a Public Certificate

Step 3
- Add a domain name to your certificate which is to be attached in the API-Gateway
- Click on Next

Step 4
- Select the validation method by which you have to validate your domain certificate
- Click on Next

Step 5

Step 6
- Review the details
- Click on Confirm and request

Step 7
- To validate your certificate via DNS you need to a CName record in the Route 53
- In our case, we have used Cpanel but the process is the same

Create a CName recordset
Step 8
- Copy the recordset from AWS console and paste it in the Route 53
- If you are using AWS set the TTL to 1

Step 9
- Once you have created the recordset click on continue

- After some time you will the status issued the certificate and your certificate is ready to be used

Create a Custom Domain Name
Step 10
- Navigate to the API-Gateway from AWS console

Step 11
- Click on Custom Domain Name on the left side of the AWS Console

Step 12
- Click on create
- Input the domain name
- Keep the configuration as it is
- Select the ACM Certificate
- Click on Create

Step 13
- As you click on create it will bring you to Domain name details where you will see all the details and API Mappings
- API Mapping is the most important this in this

API Mapping
Step 14
- Click on Configure API Mapping

Step 15

Step 16
- As you can see in the image below this is used to map the domain to API and stage
- Select the API gateway for which you want a custom domain name
- Select the stage
- You can define the path (Optional)

Point the create custom domain name to the domain
Step 17
- Copy the API Gateway domain name as we need to route the domain request to this domain which will be more clear in the next step

Step 18
- Again create a CName record and point the API gateway domain name to the domain or the subdomain name

Conclusion
Step 19
- Now as you can see when we hit the domain name with defining the path the API gives the same result as seen in step 1
