I'm trying to deploy an ECS cluster on AWS with CloudFormation, but I can't figure out how to set the cluster a custom name.
The cluster is created, but with somehow generated name, with format like stackname-ECSCluster-randomstring.
Is there a way how to set a custom name for the cluster?
The AWS::ECS::Cluster doesn't accept any parameters or tags, nor the AWS::ECS:Service.
It's kind of cosmetic thing, but it would be nice to have meaningfull names.
Clipped directly from my CloudFormation scripts. If you want to pass it in, you can do so as a parameter. Specifying the name may have been something that was added since you wrote the post. Either way, this works for me.
Resources:
  MyCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: TheNameOfTheCluster
If you want to mangle the name of the cluster you can use Fn::Join to join two (or more) strings. The following will result in a cluster named "MyClusterNamePrefix-MyClusterNameSuffix"
Resources:
  MyCluster:
    Type: AWS::ECS::Cluster
    Properties:
      ClusterName: !Join
        - "-"    # The delimiter String
        - - MyClusterNamePrefix
          - MyClusterNameSuffix
If you ever need the name back out of it you can reference elsewhere, they don't make that easy. I know this isn't exactly what you asked, but chances are you may need to reference the name elsewhere (eg UserData).
Outputs:
  MyClusterName:
    Description: The Name of My Cluster
    Value:
      Fn::Select:
        - 1
        - Fn::Split:
          - "/"
          - Fn::GetAtt:
              - MyCluster
This is because (at the time of this writing) Fn::GetAtt can only return the Cluster's ARN (scroll down to the table of supported attributes). The specification for ECS Cluster ARNs is as follows:
arn:aws:ecs:region:account-id:cluster/cluster-name
So, putting it all together:
Port to JSON as needed. It's kind of an ugly approach to it, but it works. I would keep an eye out for if/when Amazon can actually expose that as an attribute and update your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With