01 Nov 2017. 5 min read.
I needed to setup a subdomain for a REST service hosted in AWS API Gateway.
Many components had to configured correctly to get all pieces to work together. I could not find a concise instructions online and there is too much of stuff to read in AWS documentation. I will share the exact steps I did to get it working so that others doesn’t have to figure it out in a hard way like I did.
I will be using mydomain.com
as an example domain in this post.
I already own a mydomain.com purchased with namecheap.com. Also the root domain — mydomain.com is already served by Wix.com and it was setup by configuring name servers. My goal was to create subdomain api.mydomain.com to point to AWS API Gateway and still have mydomain.com to work with Wix.
Here are the step by step instructions on how I got it working:
The first step is I need to request certificates for my site in Amazon Certificate Manager (ACM). Here are the steps:
*.mydomain.com
for domain name.mydomain.com
.After approval, certificate looked like this
The next step is to add custom domain to API Gateway:
api.mydomain.com
for domain name./
to destination as my deployed API Gateway application.Here is snapshot of my API Gateway configuration
Next I defined DNS settings AWS Route 53:
mydomain.com
and clicked create. (Note domain should be root domain and not subdomain)A
Record.api.mydomain.com
as NameMy Hosted zone alias looked like ethis
I had wix nameservers under DNS settings of my domain in Namecheap. I removed Wix name servers and added AWS Route 53 Name servers. I found name servers on Hosted Zone of my domain in Route 53 “NS” type record set like below snapshot
I need to change wix domain connection type to “pointing” from dns servers. So I disconnected my domain from wix and went through domain setup wizard. I chose connection type to “pointing” and I followed these instructions provided by Wix.
For yourdomain.com, create an A record that points to: 23.236.62.147
For www.yourdomain.com, create a Cname record that points to: www174.wixdns.net
For m.yourdomain.com, create a Cname record that points to: www174.wixdns.net
So logged into Route 53 again to setup these A and CNAME record sets.
Here are the list problems I encountered and tips to solve it.
I first tried to keep Wix name servers along with Route 53 name servers. But the domain api.mydomain.com become unresolvable. Then instead of using Route 53, I tried directly adding CNAME in wix to point api.mydomain.com
to cloudfront target domain configured for my custom domain. But I got it returned this error:
ERROR The request could not be satisfied. Bad request. Generated by cloudfront (CloudFront)
So I had to remove wix name servers and switch Wix custom domain setup to pointing type configuration.
When I used root domain name in API Gateway custom domain configuration I got this SSL error:
unsupported protocol. ERR_SSL_VERSION_OR_CIPHER_MISMATCH
The error is misleading, but the real reason is the auto created cloud distribution had wrong value for alternate domain name since I used root domain name instead of subdomain name.
First I missed to add base path mapping in custom domain setup and I got Bad request. Generated by cloudfront (CloudFront)
error. This is because without base path mapping cloud front won’t know what destination to route the request. After adding the base path, It worked like a charm!
Originally published at http://erajasekar.com/posts/how-to-setup-subdomain-for-aws-api-gateway/.