Existing public Rest API deployment using AWS API Gateway with Custom Domain

Below steps we are going to perform in order to deploy API and access api via user friendly url (custom domain url)
- Get a free domain from Freenom.com
2. Generate a ssl certificate for the api FQDN (Custom Domain) using open ssl or SSLfor free or ACM as public certs are free. This certificate will used in step4 while creating custom domain for an api in APIGateway
3. Create Rest API in APIGateway console using swagger/open api file
4. Create Custom Domain for API
4. Create Route 53 public hosted zone and records which are required to route the traffic to apigateway
5. Update Freenom domain NS records with Route 53 NS records
Get a domain
We can get free domain from few providers- freenom is one of them. First create a an account by visiting and providing valid details https://www.freenom.com/en/index.html?lang=en and then search the domain which you have decided to use for the api , it will list available free domains , we can choose one of them and add to cart. (note: if details are invalid then during checkout domain will not get registered )

Once registered, we can navigate to My domains and look at the our registered domain

And also we can verify the domain existence by using nslookup
nslookup sudha-api.ml
Server: reliance.reliance
Address: 2405:201:e036:c883::c0a8:1d01Name: sudha-api.ml
Generate a ssl certificate for the api FQDN (Custom Domain)
Below options can be used to gernate ssl certificate
using openssl
(or) using Free ssl cert generator web site like https://www.sslforfree.com/ can be used
(or) using ACM
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 365
I decided to use custom domain as testapi.sudha-api.ml, so i generated cert for the same.
Once the certificates are available then Login to AWS console ,Goto ACM and import the certificate in ACM , this cert we will be referring while creating API Gateway Custom Domain .

Create a Rest API
Login to AWS console and then go to APIGateway service the choose Rest Api and import from swagger or openapi3 as shown in below screen shot ,then import the existing file which you have got from swagger hub (as its existing api the asumption here is we would be having swagger file )and then deploy your imported api.


Then Goto stages and look at the url
https://api-id.execute-api.region.amazonaws.com/stage
Example — https://nunnpdrcd4.execute-api.us-east-1.amazonaws.com/Dev-Beta

we can test get api by clicking the above url or we can use Test feature provided by API Gateway as in below screen

Create Custom Domain for API
The purpose of creating custom domain is to access the api using friendly url instead of below url
https://api-id.execute-api.region.amazonaws.com/stage
friendly url is nothing but https://customdomain/stage
Navigate to APIGateway and Click Custom domain names and then click on Create button which takes us to below screen to input below details
- domain name
- Certificate imported in step2
Once the custom domain is created then we need to map the same to API. Mapping Created Custom Domain with API is mandatory , so click on Configure API Mappings and select API and stage.


Now the API is mapped with custom domain , next step is to create Route 53 public hosted zone and records which are required to route the traffic to apigateway
Create Route 53 public hosted zone and records
Create a public hosted zone which will create NS and SOA details by default.
We need to create a A record to route traffic to our created api custom domain. In the record name section, type the same subdomain we used in the custom domain name. In our example, it’s testapi. Select “A — Routes traffic to an IPv4 and some AWS resources” as record type. Select “Alias to API Gateway API” in Value/Route traffic to. Then select the API Gateway region and choose the custom domain name id (this is the id shown in the custom domain name information page in API Gateway).




Update Freenom domain NS records with Route 53 NS records
DNS provider NS records should point to Route 53 NS records. So Get your public hosted zone NS records and update in Freenom as like below
Route 53 NS record

Freenom NS record

Now ns mapping can be verified by using nslookup
nslookup testapi.sudha-api.ml
Server: reliance.reliance
Address: 2405:201:e036:c883::c0a8:1d01
Non-authoritative answer:
Name: testapi.sudha-api.ml
Addresses: 35.169.50.11
52.5.53.157
3.227.156.57
Now the api https://customdomain/Dev-Beta is ready to serve traffic over the internet.