使用CloudFormation和AWS Console创建ECS群集时的不同行为

时间:2018-03-14 15:35:34

标签: amazon-web-services amazon-cloudformation amazon-ecs

使用 CloudFormation 创建时,没有Scale ECS Instances按钮,要缩放您需要找到 Auto Scaling组以扩展实例的实例,不是我想要的。

enter image description here

使用 AWS控制台创建时,会出现Scale ECS Instances按钮。

enter image description here

我希望在使用CloudFormation创建时拥有该按钮。

我遗漏或做错了什么?

{
  "AWSTemplateFormatVersion":"2010-09-09",
  "Description":"Create ECS Cluster, ECS Task Definitions, Lambdas, CloudWatchs for different country and environment.",
  "Parameters":{
    "CountryName":{
      "Type":"String",
      "Description":"Auto inclusion launch country name.",
      "AllowedValues":[
        "my",
        "sg"
      ]
    },
    "EnvironmentName":{
      "Type":"String",
      "Description":"An environment name that will be suffixed to resource names.",
      "AllowedValues":[
        "dev",
        "stage",
        "live"
      ]
    },
    "KeyName":{
      "Type":"AWS::EC2::KeyPair::KeyName",
      "Description":"Name of an existing EC2 KeyPair to enable SSH access to the ECS instance."
    },
    "VpcId":{
      "Type":"AWS::EC2::VPC::Id",
      "Description":"Select a VPC to deploy the ECS instance."
    },
    "SubnetId":{
      "Type":"List<AWS::EC2::Subnet::Id>",
      "Description":"Select at least two subnets in your selected VPC to deploy the ECS instance."
    },
    "InstanceType":{
      "Description":"ECS instance type",
      "Type":"String",
      "Default":"t2.micro",
      "AllowedValues":[
        "t2.micro",
        "t2.small",
        "t2.medium",
        "t2.large",
        "m3.medium",
        "m3.large",
        "m3.xlarge",
        "m3.2xlarge",
        "m4.large",
        "m4.xlarge",
        "m4.2xlarge",
        "m4.4xlarge",
        "m4.10xlarge",
        "c4.large",
        "c4.xlarge",
        "c4.2xlarge",
        "c4.4xlarge",
        "c4.8xlarge",
        "c3.large",
        "c3.xlarge",
        "c3.2xlarge",
        "c3.4xlarge",
        "c3.8xlarge",
        "r3.large",
        "r3.xlarge",
        "r3.2xlarge",
        "r3.4xlarge",
        "r3.8xlarge",
        "i2.xlarge",
        "i2.2xlarge",
        "i2.4xlarge",
        "i2.8xlarge"
      ],
      "ConstraintDescription":"Please choose a valid instance type."
    }
  },
  "Mappings":{
    "AWSRegionToAMI":{
      "us-east-1":{
        "AMIID":"ami-a7a242da"
      },
      "us-east-2":{
        "AMIID":"ami-b86a5ddd"
      },
      "us-west-1":{
        "AMIID":"ami-9ad4dcfa"
      },
      "us-west-2":{
        "AMIID":"ami-92e06fea"
      },
      "eu-west-1":{
        "AMIID":"ami-0693ed7f"
      },
      "eu-west-2":{
        "AMIID":"ami-f4e20693"
      },
      "eu-west-3":{
        "AMIID":"ami-698b3d14"
      },
      "eu-central-1":{
        "AMIID":"ami-0799fa68"
      },
      "ap-northeast-1":{
        "AMIID":"ami-68ef940e"
      },
      "ap-northeast-2":{
        "AMIID":"ami-a5dd70cb"
      },
      "ap-southeast-1":{
        "AMIID":"ami-0a622c76"
      },
      "ap-southeast-2":{
        "AMIID":"ami-ee884f8c"
      },
      "ca-central-1":{
        "AMIID":"ami-5ac94e3e"
      },
      "ap-south-1":{
        "AMIID":"ami-2e461a41"
      },
      "sa-east-1":{
        "AMIID":"ami-d44008b8"
      }
    }
  },
  "Resources":{
    "ECSCluster":{
      "Type":"AWS::ECS::Cluster",
      "Properties":{
        "ClusterName":{
          "Fn::Join":[
            "-",
            [
              {
                "Ref":"AWS::StackName"
              },
              {
                "Ref":"EnvironmentName"
              }
            ]
          ]
        }
      }
    },
    "ECSSecurityGroup":{
      "Type":"AWS::EC2::SecurityGroup",
      "Properties":{
        "GroupDescription":"Auto Inclusion Security Group",
        "VpcId":{
          "Ref":"VpcId"
        }
      }
    },
    "ECSSecurityGroupSSHinbound":{
      "Type":"AWS::EC2::SecurityGroupIngress",
      "Properties":{
        "GroupId":{
          "Ref":"ECSSecurityGroup"
        },
        "IpProtocol":"tcp",
        "FromPort":"22",
        "ToPort":"22",
        "CidrIp":"0.0.0.0/0"
      }
    },
    "ECSAutoScalingGroup":{
      "Type":"AWS::AutoScaling::AutoScalingGroup",
      "Properties":{
        "VPCZoneIdentifier":{
          "Ref":"SubnetId"
        },
        "LaunchConfigurationName":{
          "Ref":"ECSLaunchConfiguration"
        },
        "MinSize":"0",
        "MaxSize":"1",
        "DesiredCapacity":"1"
      }
    },
    "ECSLaunchConfiguration":{
      "Type":"AWS::AutoScaling::LaunchConfiguration",
      "Properties":{
        "ImageId":{
          "Fn::FindInMap":[
            "AWSRegionToAMI",
            {
              "Ref":"AWS::Region"
            },
            "AMIID"
          ]
        },
        "InstanceType":{
          "Ref":"InstanceType"
        },
        "IamInstanceProfile":{
          "Ref":"EC2InstanceProfile"
        },
        "KeyName":{
          "Ref":"KeyName"
        },
        "SecurityGroups":[
          {
            "Ref":"ECSSecurityGroup"
          }
        ],
        "UserData":{
          "Fn::Base64":{
            "Fn::Join":[
              "",
              [
                "#!/bin/bash\n",
                "echo ECS_CLUSTER=",
                {
                  "Ref":"ECSCluster"
                },
                " >> /etc/ecs/ecs.config"
              ]
            ]
          }
        }
      }
    },
    "EC2Role":{
      "Type":"AWS::IAM::Role",
      "Properties":{
        "AssumeRolePolicyDocument":{
          "Statement":[
            {
              "Effect":"Allow",
              "Principal":{
                "Service":[
                  "ec2.amazonaws.com"
                ]
              },
              "Action":[
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Path":"/",
        "ManagedPolicyArns":[
          "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
        ],
        "Policies":[
          {
            "PolicyName":"auto-inclusion",
            "PolicyDocument":{
              "Version":"2012-10-17",
              "Statement":[
                {
                  "Effect":"Allow",
                  "Action":[
                    "s3:GetObject",
                    "s3:ListBucket",
                    "s3:PutObject",
                    "s3:DeleteObject"
                  ],
                  "Resource":[
                    "*"
                  ]
                },
                {
                  "Effect":"Allow",
                  "Action":[
                    "dynamodb:*"
                  ],
                  "Resource":[
                    {
                      "Fn::Join":[
                        "",
                        [
                          "arn:aws:dynamodb:",
                          {
                            "Ref":"AWS::Region"
                          },
                          ":",
                          {
                            "Ref":"AWS::AccountId"
                          },
                          ":table/ai-process-tracking-",
                          {
                            "Ref":"EnvironmentName"
                          }
                        ]
                      ]
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
    },
    "EC2InstanceProfile":{
      "Type":"AWS::IAM::InstanceProfile",
      "Properties":{
        "Path":"/",
        "Roles":[
          {
            "Ref":"EC2Role"
          }
        ]
      }
    }
  },
  "Outputs":{
    "ecscluster":{
      "Value":{
        "Ref":"ECSCluster"
      }
    }
  }
}

2 个答案:

答案 0 :(得分:1)

更新:我在官方documentation中找到了这个。

  

如果您的群集是在2015年11月24日之后使用console first-run experience创建的,则与之关联的Auto Scaling组   可以扩展为群集创建的AWS CloudFormation堆栈   或者向下添加或删除容器实例。你可以执行此操作   从Amazon ECS控制台中进行扩展操作。

     

如果您的群集未在2015年11月24日之后使用控制台首次运行体验创建,那么您无法扩展   来自Amazon ECS 控制台的群集。但是,您仍然可以修改   Auto中与您的群集关联的现有Auto Scaling组   扩展控制台。

参考:Scaling Cluster

  

如果出现Scale ECS Instances按钮,则可以缩放您的   集群在下一步。如果没有,您必须手动调整自动   缩放组可以向上或向下扩展实例,也可以手动进行   在Amazon EC2中启动或终止容器实例   控制台。

答案 1 :(得分:0)

更新:如果您的集群未在2015年11月24日之后使用控制台首次运行体验创建,那么您无法从Amazon ECS控制台扩展集群。

ORIGINAL:

这只是一步一步解释如何获取按钮,您需要在CloudFormation模板中反映这一点。

  • 创建一个空的ECS群集,例如 my-test-cluster
  • 转到CloudFormation,使用模板创建名为 EC2ContainerService-my-test-cluster 的堆栈
  • 模板可能需要具有以下内容
Outputs:
  TemplateVersion:
    Value: '2.0.0'
  UsedByECSCreateCluster:
    Value: 'true'
相关问题