首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有单个CNAME的Access 2 AWS API网关

带有单个CNAME的Access 2 AWS API网关
EN

Stack Overflow用户
提问于 2018-09-17 23:52:17
回答 1查看 1.7K关注 0票数 1

我有一个作为customdomain.com的托管区域和两个托管在AWS上的区域性API网关。

我希望将公共CNAME配置为myapp.customdomain.com,以便根据延迟调用APIGW_REGION_ONE_EXECUTEAPI_URIAPIGW_REGION_TWO_EXECUTEAPI_URI

我该怎么做?我混淆了API上的自定义域名和53路由的CNAME记录。任何帮助或指导都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-18 08:06:24

API上的自定义域名允许它响应除AWS之外的名称(它通过SNI工作),还可以提供至少一个与您提供的名称相匹配的的证书,因此您需要定义该名称以及任何DNS记录,这样人们就可以解析API。

至于基于延迟的记录,您需要创建多个Route53记录,并在每个记录中定义延迟策略。文档展示了如何创建加权记录,以便将10%的流量转移到不同的目标:

代码语言:javascript
复制
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"]
}

在您的例子中,您需要这样的东西:

代码语言:javascript
复制
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网关或使用具有不同区域配置的多个提供者同时应用于此的位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52377091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档