在ECS容器实例

时间:2016-05-18 08:36:48

标签: amazon-web-services amazon-ec2 aws-sdk amazon-ecs

我使用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" ]}]] }
}
 }
}

1 个答案:

答案 0 :(得分:2)

您是否尝试过标记实例:

"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"}]
  }
},

我不确定语法但应该有用。