Lesson 7 of 7 Amazon API Gateway

Publishing APIs on Custom Domain Names

This lesson explains how a custom domain gives an API a stable, branded URL, such as api.example.com, in place of the generated execute-api address.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the certificate and DNS configuration that a custom domain requires for each endpoint type.
  • Explain how API mappings route paths on one domain to different APIs and stages.
  • Describe what mutual TLS and multi-Region custom domains add.

Setting up a custom domain

A custom domain name gives an API a stable, branded address, such as api.example.com, in place of the generated execute-api address. Because the domain is mapped to an API and stage, the API behind it can be replaced or versioned without changing what clients call. It is set up by the following steps.

  1. Get a certificate

    Request or import a TLS certificate in AWS Certificate Manager (ACM).

  2. Create the custom domain name

    Create the custom domain name in API Gateway and choose the certificate.

  3. Add an API mapping

    Connect the domain to an API and stage.

  4. Point DNS at the domain

    Create a DNS record, usually a Route 53 alias, pointing to the API Gateway domain.

Where the certificate must be created depends on the endpoint type of the custom domain. An edge-optimized custom domain is served through CloudFront, which reads certificates only from the us-east-1 Region, so the certificate must be in us-east-1 even when the API is in another Region. A Regional custom domain is served from the API's Region, so the certificate must be in that Region. A certificate in the wrong Region is the usual reason it does not appear in the list when the domain is created. The following table summarises the rule.

Custom domain typeCertificate RegionNotes
Edge-optimizedus-east-1API Gateway creates and manages a CloudFront distribution
RegionalThe API's own RegionYou can still put your own CloudFront distribution in front
Put in order

Set up a custom domain

Exam skills 3.1.5 · 2.2.2

Put the steps of publishing an API on a custom domain in order.

Log in to try this activity Interactive activities are free with an account.

API mappings

A custom domain is connected to APIs through API mappings, also called base path mappings. Each mapping connects a path on the domain to one API and stage. With a single mapping and an empty path, https://api.example.com/orders calls the /orders resource of the mapped API.

Several mappings on one domain let different APIs share it. For example, /v1 can map to the prod stage of the original API and /v2 to the prod stage of a rewritten API, so both versions run side by side and clients migrate at their own pace. Because clients call only the custom domain, a back-end API can be replaced by changing a mapping, without changing any client.

Mutual TLS and multi-Region APIs

Custom domains provide two further capabilities. With mutual TLS (mTLS), the domain requires each client to present an X.509 certificate during the TLS handshake, and API Gateway checks it against a trust store of certificate authorities uploaded to Amazon S3. Clients without a valid certificate are rejected before any request reaches the API, which suits business-to-business and Internet of Things (IoT) integrations where clients are known systems rather than users. Mutual TLS is available only on Regional custom domain names.

For multi-Region APIs, the same API is deployed in several Regions, each with a Regional custom domain of the same name and a certificate in that Region. Amazon Route 53 then routes each user to one of the Regions, using latency-based routing to choose the closest Region, or failover routing with health checks to move users away from a Region that is unavailable.

Scenario questions

Custom domains in practice

Exam skills 3.1.5 · 2.2.2

Practise the custom domain decisions that exam scenarios turn on.

Log in to try this activity Interactive activities are free with an account.
Worked example

One domain, two APIs

A company wants api.example.com/orders to reach the Orders API and api.example.com/customers to reach the Customers API, both Regional APIs in eu-west-1.

StepConfiguration
CertificateACM certificate for api.example.com in eu-west-1 (the API's Region; edge-optimized would need us-east-1)
Custom domain nameapi.example.com, Regional endpoint
API mappingsorders → Orders API prod stage; customers → Customers API prod stage
DNSRoute 53 alias record pointing to the custom domain's Regional target

Clients now use one stable domain while each team deploys its API independently. A frequent mistake is requesting the certificate in us-east-1 for a Regional API, which then cannot be selected.

Check yourself

An edge-optimized custom domain is created for an API in eu-west-1. In which Region must its ACM certificate be?

Show answer

US East (N. Virginia), us-east-1, because edge-optimized endpoints are served through CloudFront. A Regional custom domain uses a certificate in the API's own Region.

Exam Tips

Remember for the exam

  • To keep the same URL while switching backend APIs, use API mappings on a custom domain.
  • An edge-optimized custom domain needs its ACM certificate in us-east-1; a Regional one needs it in the API's Region.
  • A multi-Region API behind one domain name uses Regional custom domains with Route 53 latency or failover routing.