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记录。
您拥有的网络域。它的根必须在DNS中具有有效的A记录。
简而言之,如果您的域为example.com根,则example.com在继续之前需要为网站实际配置-。A记录的具体值与Cognito无关,因为这取决于您选择设置站点的方式...但是Cognito要求它存在。
似乎尝试使用带有太多点的子域会导致此错误。
这有效:
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流行的答案正确地回答了这个问题。但在更高的层面上,还有更多内容。配置依赖中有一个循环:
Cognito 需要
auth.example.comA 记录,而 Cognito 需要example.comA 记录。Aexample.com记录需要一个网站来指向,而网站需要Cognito。
为了打破这个循环,
auth.example.com,供 Cognito 独立于网站example.com区域使用。这打破了依赖循环。auth.example.com指向占位符 IP 地址的 A 记录,例如127.0.0.1. 这永远不会被实际使用。dev.auth.example.com、stage.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.com、stage-auth.example.com和 )
,可以在环境之间获得更好的隔离auth.example.com。无需担心这些下面的子域。
| 归档时间: |
|
| 查看次数: |
2656 次 |
| 最近记录: |