AWS ECS: Severe bug in ECS Service Cloudformation template
Asked Answered
A

2

1

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

Amata answered 11/9, 2018 at 6:57 Comment(0)
W
3

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.

Updated: As per this new feature (introduced on 24 Sep 2018), now you can specify the containerName and containerPort in the Service Registry.

Wily answered 11/9, 2018 at 9:48 Comment(0)
W
1

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.

Wily answered 24/9, 2018 at 22:43 Comment(1)
Probably better to edit the accepted answer with an update.Jape

© 2022 - 2024 — McMap. All rights reserved.