How to setup a custom domain name with AWS API Gateway
Map your own domain name to AWS API Gateway
When you configure an AWS API Gateway instance with one or more routes, AWS provides a custom domain name in the form of
*.execute-api.region.amazonaws.com. In this tutorial you will learn one way to use your own domain name with API Gateway.
I assume you have a basic knowledge of how API Gateway works. I’m also using HTTP API with a Lambda function as a backend integration in this example, and the steps described here should be similar for different types of APIs. You also need access to your DNS registrar to update some records.
Step 1 — Disable the default endpoint
In API Gateway console, choose the API you want to update and click Edit. Under the Default endpoint section, choose Disabled and then Save. This option prevents users to access the API using the default (AWS generated) endpoint.
Step 2 — Request a certificate for the domain
AWS needs to verify you own the domain name you’re setting up. Go to Certificate manager console and click Request a certificate. For Domain name, enter the domain name you will use, for example
api.mydomain.com and click Next. Choose the DNS validation method, skip the steps 3 and 4. Now use the data provided to update your DNS records and wait a few minutes for the validation status to become Issued.
Keep in mind that the AWS issued certificate will be valid as long as the records exist with the DNS registrar.
Step 3 — Add a custom domain name to API Gateway
Go back to API Gateway console. Under the Custom domain names section, click Create.
For Domain name, enter the domain name.
For ACM certificate, choose the certificate created in step 2.
Step 4 — Map the domain name to a stage
Select the domain created in step 3. Under API Mappings section, click Configure API mappings.
For API, select the API instance.
For Stage, select the stage if any, or $default.
Step 5 — Configure Route 53
You need to match your domain name certificate with AWS in order to use SSL/TLS. Open the Route 53 console and under the Hosted zones section, click Create hosted zone.
For Domain name, enter your domain name. Keep the default options and click Create hosted zone.
AWS provides you with some NS records. Add those records to your DNS registrar. Then, back in Route 53, click Create Record.
Keep the record name empty. The record type is A. For Value, activate the Alias toggle. Select Alias to API Gateway, the region and the endpoint. Click Create Records.
You’re all set. You may wait a few minutes for the records to become available. Then you can access the API Gateway instance using the new domain name.