【问题标题】:Set name on ECS container instance在 ECS 容器实例上设置名称
【发布时间】: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


【解决方案1】:

您是否尝试过标记实例:

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

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

【讨论】:

  • 不完全是这样,但是通过添加名称标签命名正常工作。标签添加了吗?也许语法应该是这样的: "Tags": [{ "Name": "Your name"}] ?
  • 我意识到我没有将标签放入属性级别。它的工作谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-03-30
  • 2016-07-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 2021-08-10
  • 2018-10-10
  • 2019-05-26
相关资源
最近更新 更多