How to add a custom domain for AWS Websocket API Gateway?

Viewed 1478

I have created an AWS Websocket API Gateway. It has given me an endpoint as follows:

wss://**********.execute-api.**-*****-*.amazonaws.com/dev

I need this to be changed to a custom domain. How can that be done. As I can see this URL provided by AWS is wss protocol URL.

  • How to go about it?
  • Can I use https://*****.com from route53?
  • If not, how to create a custom wss domain?
  • Or have I got to do something else
2 Answers

I found the answer. Follow these steps to add custom domain to AWS Websocket API Gateway

  1. Go to API Gateway
  2. go to "Custom Domain Names"
  3. Create a domain name. Example api.company.com
  4. Copy "API Gateway domain name"
  5. Go to Route 53
  6. Add record name with the domain name
  7. Set it to be CNAME
  8. For the value paste the "API Gateway domain name" that you had copied
  9. Now use domain name with wss:// . Example, wss://api.company.com to connect to websocket

Come back and Hit Like!

A URL represents multiple pieces of information in a compact form. A browser asked to request "https://example.com/some/path" will:

  • Look up the server address for "example.com" in a DNS service; this part doesn't know or care about the rest of the URL, it just wants an IP address
  • Connect to that server using the "https" protocol; this means talking HTTP over TLS, and defaulting to TCP port 443
  • Once connected, request the path "/some/path"

In theory, pointing another domain, say "forward.example.org" to the same server in DNS will allow the URL "https://forward.example.org/some/path" to serve the same content. In practice, many servers are set up to receive requests for multiple different domains, and serve different content, so the server needs to also have a rule for which content to serve for that content.

Using a URL like "wss://example.com" is exactly the same:

  • The domain name needs to resolve to an appropriate IP address. Since you don't want to hard-code that address, you would do this with a CNAME in an external DNS service, or an ALIAS record in Route53
  • The server needs to be expecting that host name, to know which API to serve for it. In this case, that means setting the "custom domain" setting in API Gateway.

The other step - connecting over "wss" instead of "https" protocol - doesn't change how the server is looked up, so shouldn't make any difference to the process.

Related