简体   繁体   English

在服务发现名称空间(私有托管区域)中注册AWS ECS任务

[英]Register AWS ECS task in service discovery namespace (private hosted zone)

I'm quite bad at using AWS but I'm trying to automate the set up of an ECS cluster with private DNS names in route53, using the new service discovery mechanism. 我在使用AWS方面非常不好,但是我正在尝试使用新的服务发现机制自动在route53中使用私有DNS名称设置ECS集群的设置。 I am able to click my way through the AWS UI to accomplish a DNS entry showing up in a private hosted zone but I cannot figure out the JSON parameters to add to the json for the command below to accomplish the same thing. 我可以通过AWS UI单击自己的方式来完成显示在私有托管区域中的DNS条目,但是我无法找出要添加到JSON的JSON参数以用于下面的命令来完成相同的操作。

aws ecs create-service --cli-input-json file://aws/createService.json

and below is the approximate contents of the createService.json referenced above 下面是上面引用的createService.json的大致内容

  "cluster": "clustername",
  "serviceName": "servicename",
  "taskDefinition": "taskname",
  "desiredCount": 1,

  // here is where I'm guessing there should be some DNS config referencing some
  // namespace or similar that I cannot figure out...

  "networkConfiguration": {
    "awsvpcConfiguration": {
      "subnets": [
        "subnet-11111111"
      ],
      "securityGroups": [
        "sg-111111111"
      ],
      "assignPublicIp": "DISABLED"
    }
  }

I'd be grateful for any ideas since my googling skills apparently aren't good enough for this problem as it seems. 我将不胜感激,因为我的谷歌搜索技能显然不足以解决这个问题。 Many thanks! 非常感谢!

To automatically have an ECS service register instances into a servicediscovery service you can use the serviceRegistries attribute. 要将ECS服务自动将实例注册到服务发现服务中,可以使用serviceRegistries属性。 Add the following to the ECS service definition json: 将以下内容添加到ECS服务定义json中:

{ 
    ...
    "serviceRegistries": [
       {
          "registryArn": "arn:aws:servicediscovery:region:aws_account_id:service/srv-utcrh6wavdkggqtk"
       }
    ]
}

The attribute contains a list of autodiscovery services that should be updated by ECS when it creates or destroys a task as part of the service. 该属性包含自动发现服务的列表,当ECS创建或销毁作为该服务一部分的任务时,应由ECS更新。 Each registry is referenced using the ARN of the autodiscovery service. 使用自动发现服务的ARN引用每个注册表。

To get the Arn use the AWS cli command aws servicediscovery list-services 要获取Arn,请使用AWS cli命令aws servicediscovery list-services

Strangely the documentation of the ECS service definition does not contain information about this attribute. 奇怪的是, ECS服务定义的文档不包含有关此属性的信息。 However this tutorial about service discovery does. 但是, 有关服务发现的教程可以。

As it turns out there is no support in ecs create service for adding it to the service registry, ie the route53 private hosted zone. 事实证明,ecs create service不支持将其添加到服务注册表中,即route53专用托管区域。 Instead I had to use aws servicediscovery create-service and then servicediscovery register-instance to finally get an entry in my private hosted zone. 相反,我不得不使用aws servicediscovery create-service ,然后使用servicediscovery register-instance最终在我的私有托管区域中获得一个条目。

This became a quite complicated solution so I'll instead give Terraform a shot at it since I found they recently added support for ECS service discovery and see where that takes me... 这变成了一个非常复杂的解决方案,所以我改为给Terraform一枪,因为我发现他们最近增加了对ECS服务发现的支持,并了解了带我到哪里去...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM