需要Cognito自己的域名A记录

Mar*_*rco 5 amazon-web-services amazon-cognito aws-cognito

我正在尝试为Cognito的用户池分配一个自己的域名,并且遇到一个似乎需要A记录的问题。

就我而言,我已在我的互联网域上注册了通配符,并尝试按照https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain中所述的步骤进行操作.html

现在我可以创建一个A记录,但不知道该A记录应指向何处。欢迎任何提示或技巧:)如果可以在不使用CloudFront的情况下完成此操作,那就太好了。

我尝试了CNAME等,但如上所述,需要A记录。

Piy*_*gra 8

为了处理子域,我创建了带有 IP 的 A 记录127.0.0.1,并且它正在工作。

我想auth.dev.${domain_name}.com在 cognito 中添加为自定义域,但我没有指向任何网站,dev.${domain_name}.com因此为 dev.${domain_name}.com 创建了 A 记录并指向127.0.0.1ip 地址。

参考


Mic*_*bot 5

您拥有的网络域。它的根必须在DNS中具有有效的A记录。

简而言之,如果您的域为example.com根,则example.com在继续之前需要为网站实际配置-。A记录的具体值与Cognito无关,因为这取决于您选择设置站点的方式...但是Cognito要求它存在。

  • 为什么这是一个要求?我的网站位于`www.mydomain.com`,所以这很尴尬。为什么不让人们在没有根网站的情况下设置自定义域? (4认同)
  • 好吧,我目前正在设置从 mydomain.com 到 www.mydomain.com 的重定向,所以希望这会起作用。但是,我仍然不明白使其成为根域的特殊要求背后的逻辑。我过去已经设置了 Auth0,没有必要这样做。如果它不用于任何事情,为什么他们需要它? (3认同)
  • A 记录实际上并不需要连接到为网站或类似内容提供服务的资源。对于我的用例,我想使用的子域是例如 auth.prod.example.com。我在 prod.example.com 上有其他子域,但在确切的域上没有任何子域。我遇到了这个问题,只是添加了一条指向 127.0.0.1 的 A 记录,它就消除了错误。 (2认同)

2nd*_*Lab 5

似乎尝试使用带有太多点的子域会导致此错误。

这有效:

auth.example.com

这不会:

dev.auth.example.com

此外,如果您删除并重新添加相同的域名,这似乎会导致错误。更改为不同的域有效。

我向 #awswishlist https://awswishlist.com/添加了修复此问题的请求


小智 5

与此处无关的不是域。子域位于您输入的子域之下的级别

  • 如果输入auth.example.com,则需要A记录 example.com
  • 如果输入auth.qa.example.com,则需要A记录qa.example.com
  • 如果输入foo.bar.qa.example.com,则需要A记录bar.qa.example.com

  • 这里相关的关注点是,如果您没有站点(例如.com),但您确实想使用 auth.example.com 作为身份验证域,那么您将 example.com 指向什么?记录到? (2认同)

Joh*_*hee 5

流行的答案正确地回答了这个问题。但在更高的层面上,还有更多内容。配置依赖中有一个循环:

Cognito 需要auth.example.comA 记录,而 Cognito 需要example.comA 记录。Aexample.com记录需要一个网站来指向,而网站需要Cognito。

为了打破这个循环,

  1. 创建一个新的 Route 53 区域auth.example.com,供 Cognito 独立于网站example.com区域使用。这打破了依赖循环。
  2. 创建一条auth.example.com指向占位符 IP 地址的 A 记录,例如127.0.0.1. 这永远不会被实际使用。
  3. 现在,您可以为每个环境的 Cognito 自定义域创建 A 记录,例如dev.auth.example.comstage.auth.example.com或。prod.auth.example.com

以下 Terraform 示例将所有这些组合在一起,创建一个 Cognito 自定义域prod.auth.example.com

# Pre-existing hosted zone created by Route53 Registrar
data "aws_route53_zone" "main" {
  name = "example.com"
}

# Create a new Route 53 zone auth.example.com
#
# Actually, Route 53 zone creation belongs in a separate Terraform
# module where it can be shared by multiple environments.

resource "aws_route53_zone" "auth" {
  name = "auth.example.com"
}

resource "aws_route53_record" "auth-ns" {
  zone_id = data.aws_route53_zone.main.zone_id
  name    = "auth.example.com"
  type    = "NS"
  ttl     = "30"
  records = aws_route53_zone.auth.name_servers
} As it is now,
# `terraform destroy` will destroy zone auth.example.com, leaving the other environments in the lurch.

# Only the name servers in the auth.example.com zone NS record know where
# to find auth.example.com. Add NS record in example.com pointing to the
# auth.example.com zone name servers. Now auth.example.com can
# be found through example.com.
resource "aws_route53_record" "auth-a" {
  zone_id = aws_route53_zone.auth.zone_id
  name    = "auth.example.com"
  type    = "A"
  ttl     = 300
  records = ["127.0.0.1"]  # Placeholder that is never used
}

# Route 53 zone auth.example.com setup done

module "acm" {
  source = "terraform-aws-modules/acm/aws"

  domain_name               = "prod.auth.example.com"
  zone_id                   = aws_route53_zone.auth.zone_id
  subject_alternative_names = []
  wait_for_validation       = true
}

resource "aws_cognito_user_pool" "this" {
  name = "prod-cognito"
}

resource "aws_cognito_user_pool_domain" "this" {
  depends_on      = [aws_route53_record.auth-a]
  domain          = "prod.auth.example.com"
  certificate_arn = module.acm.this_acm_certificate_arn
  user_pool_id    = aws_cognito_user_pool.this.id
}

resource "aws_route53_record" "subdomain-a" {
  zone_id = aws_route53_zone.auth.zone_id
  name    = "prod.auth.example.com"
  type    = "A"
  alias {
    evaluate_target_health = false
    name                   = aws_cognito_user_pool_domain.this.cloudfront_distribution_arn
    # Every CloudFront distribution's zone ID is Z2FDTNDATAQYW2
    zone_id = "Z2FDTNDATAQYW2"
  }
}
Run Code Online (Sandbox Code Playgroud)

仍有一些工作要做:您还需要使用aws_cognito_user_pool_client. 我省略了这一点,因为应用程序客户端与自定义域无关。

更新:我发现通过为每个环境创建托管区域(例如 dev-auth.example.comstage-auth.example.com和 ) ,可以在环境之间获得更好的隔离auth.example.com。无需担心这些下面的子域。