【发布时间】:2016-09-14 15:04:10
【问题描述】:
我正在使用 ECS 使用 Cloudformation 创建集群和容器实例,但我不知道如何设置创建的 ECS 容器实例的名称。
知道在哪里设置名称吗?这是我的脚本。
{
"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" ]}]] }
}
}
}
【问题讨论】:
-
不清楚 - 你说你想要一个 ECS 集群,但你定义了一个 EC2 实例。你不应该有一个类型
AWS::ECS::Cluster并且在你的任务定义中具有name属性的容器 -
您的集群需要一个容器,它是一个 ec2 实例,这有什么问题?
-
是的,但这就是亚马逊在您使用 ECS 时为您所做的 - 您可以使用 EC2 管理自己并部署您的容器,或者使用 ECS 而不管理低级别实例
-
我正在从头开始创建整个集群和容器,没有任何手动操作。无论如何,这是关于如何为容器实例命名的话题 XD
-
是的,但是您提到了 ECS,但在这里您没有使用该服务
标签: amazon-web-services amazon-ec2 aws-sdk amazon-ecs