CNAMEAlreadyExists:将子域指向新帐户中的分发

CNAMEAlreadyExists: pointing subdomain to distribution in new account

我正在尝试将一个子域指向一个新的发行版。我有两个帐户:legacynew

legacy 帐户拥有这些资源:

帐户拥有这些资源:

我希望最终设置为 a.foo.com CNAME 到 qrs.cloudfront.net。 (我不明白为什么 CloudFront 发行版需要知道它的 CNAME 是什么,这可能是我不理解下面错误的部分原因。)

所以我正在关注 these official docs。我正在尝试通过将 *.foo.com 设置为新 CloudFront 分配的备用域名来执行第 3 步。

但是我得到以下错误:

com.amazonaws.services.cloudfront.model.CNAMEAlreadyExistsException: One or more of the CNAMEs you provided are already associated with a different resource. (Service: AmazonCloudFront; Status Code: 409; Error Code: CNAMEAlreadyExists;)

您遵循的说明是将子域迁移到同一帐户内的不同分布

You cannot add an alternate domain name to a CloudFront distribution if the alternate domain name already exists in another CloudFront distribution, even if your AWS account owns the other distribution.

However, you can add a wildcard alternate domain name, such as *.example.com, that includes (that overlaps with) a non-wildcard alternate domain name, such as www.example.com. Overlapping domain names can be in the same distribution or in separate distributions as long as both distributions were created by using the same AWS account. (emphasis added)

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CNAMEs.html#alternate-domain-names-wildcard

不可能在多个帐户之间存在通配符歧义,而您正在尝试做的就是设置这样的条件。它不受支持,因为它是一个安全漏洞。

I don't understand why the Cloudfront distribution needs to know what things CNAME to it, which is maybe part of the reason I'm not understanding the error below.

HTTP 和 DNS 的交互方式使得目标服务器不知道将浏览器引导至其所连接的服务器地址的 DNS 解析路径。服务器只能通过 HTTP Host header 和使用 HTTPS 时 SNI 字段的值来识别浏览器请求的站点—— dzczcexample.cloudfront.net 中间主机名在过程。备用域名配置设置(不幸的是,由于遗留原因,不准确地也称为 CNAME)是 CloudFront —— 一个庞大的 globally-distributed 系统 —— 使用以确定哪个特定分配应该处理请求,所以备用域对于整个 CloudFront 中的一个分配,名称只能设置为 foo.example.com

如上所述,*.example.com 只能在与 foo.example.com 相同帐户内的 CloudFront 分配上设置,否则会造成域劫持漏洞。

解决方法有点微妙,但可以做到。

  • 设置新的 CloudFront 分配,不设置备用域名,并等待它转换到 Deployed 状态。
  • 更改 DNS 以指向为新分发分配的主机名。这不会像您假设的那样:由于上面提到的 Host header/SNI 映射,流量实际上仍将由旧分配处理......但是在继续之前需要更改此设置。
  • 从旧分配的备用域名设置中删除主机名并保存更改。
  • 将主机名添加到新分配的备用域名设置中并保存更改。您应该会在短时间内收到错误,之后更改将被接受,流量将由新分配提供服务。

您将需要设置两个测试分发版和一个虚拟子域(可能完全在不同的域中)并完成这些步骤以熟悉该过程。当我之前完成这个过程时,由此产生的中断是短暂的,因为你不是在创建一个新的分布(这需要一些时间),而是简单地改变一个稳定分布的属性,然后再改变另一个。

我 运行 在尝试创建 login.example.com 子域以使用 Cognito Hosted UI 进行用户授权时遇到此错误。我已经为 example.com 设置了一个用于 SSL 保护的 CloudFront 分配。我能够通过将备用域名之一从通用 *.example.com 更改为 www.example.com 来解决错误