0Pricing
Serverless Backend with AWS Lambda & API Gateway · 课时

自定义域名与边缘优化

为 API 配置自定义域名,并利用边缘优化端点提升全球性能

自定义域名与边缘优化 是 CoddyKit 上的免费 Serverless Backend with AWS Lambda & API Gateway 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Serverless Backend with AWS Lambda & API Gateway 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Serverless Backend with AWS Lambda & API Gateway 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Your API's Own Address

When you deploy an API Gateway API, AWS provides a default URL. It looks something like https://abcdef123.execute-api.us-east-1.amazonaws.com/prod.

While functional, this URL isn't very user-friendly or brandable. This lesson shows how to use your own domain name!

The Default API Address

Every API Gateway API automatically gets a unique endpoint URL. This URL includes a random ID, the AWS region, and amazonaws.com.

  • Example: https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}
  • It works immediately after deployment.
  • Great for testing, but not ideal for public-facing APIs.

Benefits of Custom Domains

Using a custom domain name for your API offers several advantages:

  • Branding: Use your company's domain (e.g., api.yourcompany.com).
  • Memorability: Easier for users and developers to remember and type.
  • Flexibility: You can change your backend API without changing the public URL.
  • SEO (for web APIs): Helps with search engine optimization.

Securing Your Custom Domain

Before you can use a custom domain, you need an SSL/TLS certificate. This certificate encrypts communication and proves your API's identity.

  • AWS Certificate Manager (ACM) can provision free public SSL certificates.
  • You can also import your own certificate.
  • The certificate must be in the US East (N. Virginia) region for edge-optimized APIs.

Configuring Your Custom Domain

Once you have an SSL certificate, you can configure your custom domain in the API Gateway console.

You'll specify your domain name (e.g., api.example.com) and associate it with the ACM certificate. API Gateway will then create a domain name and provide a DNS target (a CloudFront distribution domain name).

Connecting to Your API

A custom domain needs to know which API Gateway API to route requests to. This is done using base path mappings.

You define a base path (e.g., /v1 or /) and map it to a specific API Gateway API and stage (e.g., prod).

  • api.example.com/v1 -> my-api/prod
  • api.example.com/users -> users-api/prod

Pointing Your Domain

The final step is to update your domain's DNS records. You need to create a CNAME record (or A record if using Route 53 alias) that points your custom domain to the DNS target provided by API Gateway.

This tells the internet that requests for api.example.com should go to the API Gateway's CloudFront distribution.

Global Performance with Edge Optimization

API Gateway offers different endpoint types. Edge-optimized endpoints are the default for REST APIs and are designed for global clients.

They use Amazon CloudFront, AWS's content delivery network (CDN), to route requests through the nearest edge location to your users.

This reduces latency and improves performance for geographically dispersed clients.

CloudFront in Action

When you use an edge-optimized endpoint:

  1. A user's request hits the nearest CloudFront edge location.
  2. CloudFront forwards the request to your API Gateway in the AWS region.
  3. The response is cached at the edge location (if configured) and returned to the user.

This caching and proximity routing significantly speeds up API calls for global users.

Choosing the Right Endpoint Type

API Gateway also supports Regional endpoints. These are best when all your API consumers are in the same AWS region as your API.

  • Edge-Optimized: Default for REST APIs, uses CloudFront, best for global users.
  • Regional: Best for clients in the same region, can be fronted by your own CloudFront distribution for more control.

HTTP APIs only support Regional endpoints by default, but you can add CloudFront yourself.

Custom Domain Check

You want to use api.mydomain.com for your API Gateway API, which will be accessed by users worldwide. Which of the following statements is TRUE?

Recap: Custom Domains & Edge

In this lesson, we learned how to give your API Gateway APIs a professional, branded look using custom domain names. We covered the steps from SSL certificates to DNS configuration.

We also explored edge-optimized endpoints, understanding how they leverage CloudFront to deliver your API with low latency to users across the globe. You now know when to choose between edge-optimized and regional endpoints.

常见问题解答

「自定义域名与边缘优化」课时是免费的吗?

是的 — 「自定义域名与边缘优化」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Serverless Backend with AWS Lambda & API Gateway 课程的其余内容,请升级到 CoddyKit PRO。 Serverless Backend with AWS Lambda & API Gateway 课程共包含 4 节课。

「自定义域名与边缘优化」这节课中我会学到什么?

为 API 配置自定义域名,并利用边缘优化端点提升全球性能 你通过在浏览器中直接运行的动手代码来练习 Serverless Backend with AWS Lambda & API Gateway,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Serverless Backend with AWS Lambda & API Gateway 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Serverless Backend with AWS Lambda & API Gateway 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「自定义域名与边缘优化」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Serverless Backend with AWS Lambda & API Gateway 课中编写并运行代码吗?

能。每节 Serverless Backend with AWS Lambda & API Gateway 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 缓存与限流
  2. 请求/响应转换
  3. 自定义域名与边缘优化
  4. 用于实时通信的 WebSocket API
← 返回 Serverless Backend with AWS Lambda & API Gateway