带有Api网关的AWS Route 53通配符子域 [英] AWS Route 53 wildcard subdomain with Api gateway

查看:151
本文介绍了带有Api网关的AWS Route 53通配符子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AWS Route53 DNS服务上有一个托管区域名称example.com. 我有多个子域记录集,例如:

I have a Hosted zone name example.com on AWS Route53 DNS service. I have multiple subdomain record sets like:

api.example.com - type A - ALIAS xxx.cloudfront.net
www.example.com - type A - ALIAS xxx.cloudfront.net
app.example.com - type A - ALIAS xxx.cloudfront.net

所有记录均指向由Api Gateway自定义域生成的Cloudfront.

All the records point to a Cloudfront generated by Api Gateway Custom Domain.

我想为我的所有用户提供一个自定义子域:

I want to offer a custom subdomain to all of my users:

USERNAME.example.com
alice.example.com
bob.example.com
...

我不知道所有用户的用户名,并且其中可能有1000个用户.

I do not know in advance the username of all my users and there can be 1000s of them.

如何设置Route53将所有未定义的子域路由到特定的Cloudfront => Api Gateway => AWS Lambda实例?

How can I setup Route53 to route all non defined subdomains to a specific Cloudfront => Api Gateway => AWS Lambda instance?

推荐答案

来自Amazon route53文档: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DomainNameFormat.html

From amazon route53 docs: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DomainNameFormat.html

在托管区域和记录的名称中使用星号(*),您可以 创建名称中包含*的托管区域.请注意以下几点:

Using an Asterisk (*) in the Names of Hosted Zones and Records You can create hosted zones that include * in the name. Note the following:

您不能在域名的最左侧标签中包含*.为了 例如,不允许使用* .example.com.

You can't include an * in the leftmost label in a domain name. For example, *.example.com is not allowed.

如果在其他位置加上*,DNS会将其视为*字符 (ASCII 42),而不是通配符.

If you include * in other positions, DNS treats it as an * character (ASCII 42), not as a wildcard.

您还可以创建名称中包含*的记录. DNS对待 *字符可以是通配符,也可以是*字符(ASCII 42),具体取决于它在名称中的显示位置.注意以下 在记录名称中将*用作通配符的限制:

You can also create records that include * in the name. DNS treats the * character either as a wildcard or as the * character (ASCII 42), depending on where it appears in the name. Note the following restrictions on using * as a wildcard in the name of records:

*必须替换域名中最左边的标签,例如, .example.com.它不能替换任何中间标签,例如marketing. .example.com.

The * must replace the leftmost label in a domain name, for example, .example.com. It can't replace any of the middle labels, for example, marketing..example.com.

*必须替换整个标签.例如,您不能指定 prod.example.com或prod .example.com.

The * must replace the entire label. For example, you can't specify prod.example.com or prod.example.com.

对于具有NS类型的记录,不能将*用作通配符.

You can't use the * as a wildcard for records that have a type of NS.

对于记录,如果在最左边以外的任何位置加上* 域名中的标签,DNS将其视为*字符(ASCII 42), 而不是通配符.

For records, if you include * in any position other than the leftmost label in a domain name, DNS treats it as an * character (ASCII 42), not as a wildcard.

之后,您可以在API中获取请求的子域并对其执行特定操作,例如,使用子域按用户名选择用户.

After that you can get the subdomain of the request within your API and perform a certain action for it, e.g., select a user by username using subdomain.

<罢工> 编辑: 不幸的是,AWS API Gateway不支持通配符子域名,正如我们在此链接的第一点所看到的: Api网关已知问题

Unfortunately AWS API Gateway does not support wild-card subdomain name as we can see in the first point of this link: Api Gateway Known Issues

现在,AWS API网关支持通配符子域: API网关通配符子域谢谢@justin裁缝

EDIT 2: Now the AWS API Gateway has support for wild-card subdomains: API Gateway Wild Card sub domain Thanks @justin tailor

这篇关于带有Api网关的AWS Route 53通配符子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆