在 ECS 容器实例上设置名称

Set name on ECS container instance

我正在使用 ECS 创建集群和使用 Cloudformation 的容器实例,但我不知道如何设置创建的 ECS 容器实例的名称。

知道在哪里设置名称吗?这是我的scipt。

      {
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "Amazon ECS Preview Quickstart Template",

 "Parameters" : {

  "ClusterName": {
  "Description" : "Name of your Amazon ECS Cluster",
  "Type" : "String",
  "ConstraintDescription" : "must be a valid Amazon ECS Cluster.",
  "Default" : "xxxxx"
},

"InstanceType" : {
  "Description" : "Container Instance type",
  "Type" : "String",
  "Default" : "t2.medium",
  "AllowedValues" : [ "t2.micro", "t2.small", "t2.medium", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge" ],
  "ConstraintDescription" : "must be a valid EC2 instance type."
}
   },

  "Mappings" : {
"AWSInstanceType2Arch" : {
  "t2.medium"   : { "Arch" : "HVM64"  }
},

"AWSRegionArch2AMI" : {
  "eu-west-1"      : { "HVM64" : "ami-f66de585"  }
}

  },

  "Resources" : {

"ContainerInstance" : {
  "Type": "AWS::EC2::Instance",
  "Properties": {
    "IamInstanceProfile" : { "Ref" : "ECSIamInstanceProfile" },
    "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
      { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
    "InstanceType"   : { "Ref" : "InstanceType" },
    "SecurityGroups" : [ "xxxx","xxxx", "xxxx" ],
    "KeyName"        : { "Ref" : "KeyName" },
    "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash -xe\n",
      "echo ECS_CLUSTER=", { "Ref" : "ClusterName" },
      " >> /etc/ecs/ecs.config\n"
    ]]}}
  }
},
"ECSIamInstanceProfile" : {
  "Type" : "AWS::IAM::InstanceProfile",
  "Properties" : {
    "Path" : "/",
    "Roles" : ["ecsInstanceRole"]
  }
}
  },

 "Outputs" : {
  "ECSInstance" : {
    "Description" : "eu-west-1",
     "Value" : { "Fn::Join" : ["", ["ssh ec2-user@", { "Fn::GetAtt" :     [ "ContainerInstance", "PublicDnsName" ]}]] }
}
 }
}

您是否尝试过标记实例:

"ContainerInstance" : {
  "Type": "AWS::EC2::Instance",
  "Properties": {
    "IamInstanceProfile" : { "Ref" : "ECSIamInstanceProfile" },
    "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
      { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] },
    "InstanceType"   : { "Ref" : "InstanceType" },
    "SecurityGroups" : [ "xxxx","xxxx", "xxxx" ],
    "KeyName"        : { "Ref" : "KeyName" },
    "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash -xe\n",
      "echo ECS_CLUSTER=", { "Ref" : "ClusterName" },
      " >> /etc/ecs/ecs.config\n"
    ]]}},
    "Tags": [{"key": "Name", "value": "Your name"}]
  }
},

我不确定语法,但应该可以。