我有一个托管区域作为customdomain.com
和2个区域API网关托管在AWS上。
我想将常见的CNAME
配置为myapp.customdomain.com
,根据延迟调用APIGW_REGION_ONE_EXECUTEAPI_URI
和APIGW_REGION_TWO_EXECUTEAPI_URI
。
我怎样才能做到这一点?我对API网关上的自定义域名与Route 53 CNAME
记录感到困惑。任何帮助或指导都非常感谢。
API网关上的自定义域名允许它响应除AWS提供的名称之外的名称(它通过SNI工作),并且还提供至少一个与您提供的名称匹配的SAN的证书,因此您需要定义该名称以及任何DNS记录,以便人们可以解析API网关。
对于基于延迟的记录,您需要创建多个Route53记录并在每个记录中定义延迟策略。 aws_route53_record
docs显示如何创建加权记录,将10%的流量转移到不同的目标:
resource "aws_route53_record" "www-dev" {
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "www"
type = "CNAME"
ttl = "5"
weighted_routing_policy {
weight = 10
}
set_identifier = "dev"
records = ["dev.example.com"]
}
resource "aws_route53_record" "www-live" {
zone_id = "${aws_route53_zone.primary.zone_id}"
name = "www"
type = "CNAME"
ttl = "5"
weighted_routing_policy {
weight = 90
}
set_identifier = "live"
records = ["live.example.com"]
}
在你的情况下,你会想要这样的东西:
data "aws_region" "region_one" {}
data "aws_route53_zone" "selected" {
name = "example.com."
}
resource "aws_api_gateway_domain_name" "example" {
domain_name = "api.example.com"
certificate_name = "example-api"
certificate_body = "${file("${path.module}/example.com/example.crt")}"
certificate_chain = "${file("${path.module}/example.com/ca.crt")}"
certificate_private_key = "${file("${path.module}/example.com/example.key")}"
}
resource "aws_route53_record" "region_one" {
zone_id = "${data.aws_route53_zone.selected.zone_id}"
name = "${aws_api_gateway_domain_name.region_one.domain_name}"
type = "A"
latency_routing_policy {
region = "${data.aws_region.region_one.name}"
}
set_identifier = "${data.aws_region.region_one.name}"
alias {
name = "${aws_api_gateway_domain_name.region_one.regional_domain_name}"
zone_id = "${aws_api_gateway_domain_name.region_one.regional_zone_id}"
evaluate_target_health = true
}
}
并将您放置在创建每个API网关的位置或使用具有不同区域配置的多个提供程序同时应用这两个API网关。