使用 CloudFormation 和 AWS 控制台创建 ECS 集群时的不同行为
Different behavior when create ECS cluster using CloudFormation and AWS Console
使用 CloudFormation 创建时,没有 Scale ECS Instances
按钮,要扩展实例,您需要找到 Auto Scaling Group 缩放我不想要的实例。
使用 AWS 控制台 创建时,有一个 Scale ECS Instances
按钮。
我想在使用 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"
}
}
}
}
更新:我在官方documentation中找到了这个。
If your cluster was created with the console first-run experience after November 24th, 2015, then the Auto Scaling group associated with
the AWS CloudFormation stack created for your cluster can be scaled up
or down to add or remove container instances. You can perform this
scaling operation from within the Amazon ECS console.
If your cluster was not created with the console first-run experience after November 24th, 2015, then you cannot scale your
cluster from the Amazon ECS console. However, you can still modify
existing Auto Scaling groups associated with your cluster in the Auto
Scaling console.
If a Scale ECS Instances button appears, then you can scale your
cluster in the next step. If not, you must manually adjust your Auto
Scaling group to scale up or down your instances, or you can manually
launch or terminate your container instances in the Amazon EC2
console.
更新:如果您的集群不是在 2015 年 11 月 24 日之后首先使用控制台 运行 体验创建的,那么您将无法从 Amazon ECS 控制台扩展您的集群。
原创:
这只是如何获取按钮的分步说明,您需要在 CloudFormation 模板中反映这一点。
- 创建一个空的ECS集群,如my-test-cluster
- 转到 CloudFormation,并使用您的模板创建名为 EC2ContainerService-my-test-cluster 的堆栈
- 模板可能需要具有以下内容
Outputs:
TemplateVersion:
Value: '2.0.0'
UsedByECSCreateCluster:
Value: 'true'
使用 CloudFormation 创建时,没有 Scale ECS Instances
按钮,要扩展实例,您需要找到 Auto Scaling Group 缩放我不想要的实例。
使用 AWS 控制台 创建时,有一个 Scale ECS Instances
按钮。
我想在使用 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"
}
}
}
}
更新:我在官方documentation中找到了这个。
If your cluster was created with the console first-run experience after November 24th, 2015, then the Auto Scaling group associated with the AWS CloudFormation stack created for your cluster can be scaled up or down to add or remove container instances. You can perform this scaling operation from within the Amazon ECS console.
If your cluster was not created with the console first-run experience after November 24th, 2015, then you cannot scale your cluster from the Amazon ECS console. However, you can still modify existing Auto Scaling groups associated with your cluster in the Auto Scaling console.
If a Scale ECS Instances button appears, then you can scale your cluster in the next step. If not, you must manually adjust your Auto Scaling group to scale up or down your instances, or you can manually launch or terminate your container instances in the Amazon EC2 console.
更新:如果您的集群不是在 2015 年 11 月 24 日之后首先使用控制台 运行 体验创建的,那么您将无法从 Amazon ECS 控制台扩展您的集群。
原创:
这只是如何获取按钮的分步说明,您需要在 CloudFormation 模板中反映这一点。
- 创建一个空的ECS集群,如my-test-cluster
- 转到 CloudFormation,并使用您的模板创建名为 EC2ContainerService-my-test-cluster 的堆栈
- 模板可能需要具有以下内容
Outputs:
TemplateVersion:
Value: '2.0.0'
UsedByECSCreateCluster:
Value: 'true'