使用 ECS Fargate 的服务发现

Service discovery using ECS Fargate

我在 ECS Fargate 运行 中有 2 个服务。

我已经使用私有 dns 命名空间设置了服务发现,因为我的所有服务都在私有子网中。

当我尝试从另一个访问我的配置容器时,出现以下错误。

http://config.qcap-prod:50050/config: Get "http://config.qcap-prod:50050/config": dial tcp: lookup config.qcap-prod on 10.0.0.2:53: no such host

下面是我的 Terraform

resource "aws_service_discovery_service" "config" {
  name = "config"

  dns_config {
    namespace_id = aws_service_discovery_private_dns_namespace.qcap_prod_sd.id

    dns_records {
      ttl  = 10
      type = "A"
    }
  }

  health_check_custom_config {
    failure_threshold = 1
  }
}

我还需要执行其他步骤才能使用 Fargate 从 ECS 中的另一个容器访问我的容器吗?

我的命名空间的 terraform 代码是:

resource "aws_service_discovery_private_dns_namespace" "qcap_prod_sd" {
  name        = "qcap.prod"
  description = "Qcap prod service discovery"
  vpc         = module.vpc.vpc_id
}

解决这个问题的方法是添加

module "vpc" {
  enable_dns_support = true
  enable_dns_hostnames = true
}

在 vpc 模块中的模块块中,允许在我的 VPC 中解析 DNS 主机名