2016-05-18 49 views
0

我正在使用ECS创建使用Cloudformation的集群和容器实例,但我不知道如何设置创建的ECS容器实例的名称。在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 [email protected]", { "Fn::GetAtt" :  [ "ContainerInstance", "PublicDnsName" ]}]] } 
} 
} 
} 
+0

不清楚 - 你说你想要一个ECS集群,但你定义了一个EC2实例。不应该有'AWS :: ECS :: Cluster'类型,并且在您的任务定义中,具有'name'属性 –

+0

的容器需要一个容器,它是一个ec2实例,那有什么问题? – paul

+0

是的,但那就是当你使用ECS时亚马逊为你做的事情 - 你可以用EC2管理自己并部署你的容器或者使用ECS而不管理低级别的实例 –

回答

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

我不知道有关语法,但应该工作。

+0

没有,不工作。你以前试过了吗? – paul

+0

不完全是这种方式,但命名通过添加名称标签正常工作。标签已添加?也许语法应该是这样的:“Tags”:[{“Name”:“Your name”}]? –

+0

简单的语法错误 – paul