AWS ECS: Severe bug in ECS Service Cloudformation template

佐手、 提交于 2019-12-11 04:13:35

问题


Trying to create an ECS service using cloudformation via the following manifest that has the appropriate imports

 UIService:
        Type: AWS::ECS::Service
        Properties:
          Cluster: !ImportValue ECSClusterName
          DesiredCount: 1
          LaunchType: EC2
          LoadBalancers:
            - ContainerName: !ImportValue UIContainerName
              ContainerPort: '80'
              TargetGroupArn: !ImportValue UITGArn
          ServiceName: ui-service
          ServiceRegistries:
           - RegistryArn: arn:aws:servicediscovery:eu-west-1:944094092130:service/srv-oIclu40KCKM3esez7
          TaskDefinition: !ImportValue UITaskArn

This fails with the following message:

When specifying 'host' or 'bridge' for networkMode, values for 'containerName' and 'containerPort' must be specified from the task definition.

However when I add the wanted values (in the serviceregistry property where it makes me assume they are needed ?)

  UIService:
    Type: AWS::ECS::Service
    Properties:
      Cluster: !ImportValue ECSClusterName
      DesiredCount: 1
      LaunchType: EC2
      LoadBalancers:
        - ContainerName: !ImportValue UIContainerName
          ContainerPort: '80'
          TargetGroupArn: !ImportValue UITGArn
      ServiceName: ui-service
      ServiceRegistries:
       - RegistryArn: arn:aws:servicediscovery:eu-west-1:944094092130:service/srv-oIclu40KCKM3esez7
         ContainerName: !ImportValue UIContainerName
         ContainerPort: '80'
      TaskDefinition: !ImportValue UITaskArn

... I get the following failure:

Encountered unsupported property ContainerName


回答1:


This is a bug from AWS, in which the cloudformation is not supporting containerName and containerPort attribute currently. Here is the official docs for ServiceRegistry, and here is the docs for cloudformation. If I am not wrong, when service discovery was released, it only supported awsvpc networking mode and bridge/host was added later. It explains why we are having such discrepancy.

For the time being, you can create the basic ECS cloudformation, and update accordingly using CLI/API/SDK, or you can wait for sometimes so that AWS team will add support for the same.




回答2:


As per latest feature (introduced today), now you can specific the containerName and containerPort in ServiceRegistry.

I have quickly tested and it seems working just fine.



来源:https://stackoverflow.com/questions/52270322/aws-ecs-severe-bug-in-ecs-service-cloudformation-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!