AWS ECS - Unable to specify service name in cloudformation template

856 views Asked by At

I am trying to create a AWS - ECS service using cloudformation template

  "service": {
  "ServiceName": "XXX",
  "Type": "AWS::ECS::Service",
  "DependsOn": [
    "AutoScalingGroup"
  ],
  "Properties": {
    "Cluster": {
      "Ref": "ECSCluster"
    },
    "DesiredCount": "1",

    "TaskDefinition": {
      "Ref": "taskdefinition"
    }
  }
},

But I am getting an error.

Failed: Invalid template resource property 'ServiceName'

I had same problem when using Name/serviceName. I can see serviceName is a parameter based on docs. But couldn't figure out why it fails. It works if I don't specify name. But I need to specify name so that I can use the same name in a different system that updates the service.

Could you please help?

1

There are 1 answers

0
NHol On BEST ANSWER

This is slightly confusing, but the service name is set by the name of the resource you create. There is no ServiceName or Name property. The following will create an ECS service with the name MyService.

"MyService": {
  "Type": "AWS::ECS::Service",
  "DependsOn": [
    "AutoScalingGroup"
  ],
  "Properties": {
    "Cluster": {
      "Ref": "ECSCluster"
    },
    "DesiredCount": "1",
    "TaskDefinition": {
      "Ref": "taskdefinition"
    }
  }
}

Obviously if you refer to your service within the CloudFormation template you will also need to update your references.