Search code examples
amazon-web-servicesaws-cloudformationamazon-ecs

AWS ECS CloudFormation unable to create service with service discovery registry


I have the following lines in my stack template:

Service:
        Type: AWS::ECS::Service
        DependsOn: ListenerRule
        Properties:
            LaunchType: EC2
            ServiceRegistries:
                - RegistryArn: {"Fn::GetAtt": [ServiceDiscovery, Arn]}...
ServiceDiscovery:
      Type: "AWS::ServiceDiscovery::Service"
      Properties:
        Description: Service discovery registry
        DnsConfig:
          DnsRecords: [{"Type": "SRV", "TTL": 100}]
          NamespaceId:
            Fn::ImportValue: PrivateDNS
        Name: ping-service

Task definition network mode = "host".

When I push the template I see the following error: When specifying 'host' or 'bridge' for networkMode, values for 'containerName' and 'containerPort' must be specified from the task definition

However if registry properties 'containerName' and 'containerPort' are set then it throws another error: Encountered unsupported property containerName

How can service discovery registry be created with CloudFormation?


Solution

  • It's not possible to specify those properties from CloudFormation yet. As seen in the developer guide for ECS you have to specify containerName from the serviceRegistries parameter. But when we look at the CloudFormation ServiceRegistry documentation we can't find those options:

    {
      "Port" : Integer,
      "RegistryArn" : String
    }
    

    As per this new feature, now you can specify the containerName and containerPort in the Service Registry.