[英]Cloudformation Stack Template Conditions
How can I create a Cloudformation Template with Conditions clause to create 10 instances as a parameter. 如何使用带有条件子句的Cloudformation模板创建10个实例作为参数。
I have used the following example for upto 5 instances. 我已将以下示例用于最多5个实例。 But how can I use it for more than 5?
但是我怎么能使用超过5次呢? It depends on how we create our Conditions clause.
这取决于我们如何创建条件子句。
Conditions:
Launch1: !Equals [1, 1]
Launch2: !Not [!Equals [1, !Ref InstanceCount]]
Launch3: !Or
- !Not [!Equals [1, !Ref InstanceCount]]
- !Not [!Equals [2, !Ref InstanceCount]]
Launch4: !Or
- !Equals [4, !Ref InstanceCount]
- !Equals [5, !Ref InstanceCount]
Launch5: !Equals [5, !Ref InstanceCount]
Can you help me expand this example upto 10 instances? 您能否帮助我将此示例扩展到10个实例?
I highly suggest you rely on AutoScaling Groups ( AWS::AutoScaling::AutoScalingGroup ). 我强烈建议您依靠AutoScaling组( AWS :: AutoScaling :: AutoScalingGroup )。 This way you'll be able to reference the instance count using the
DesiredCapacity
property. 这样,您将能够使用
DesiredCapacity
属性引用实例计数。 You'll have a ton of other benefits by doing so too. 这样做还可以带来很多其他好处。
EDIT: but if you still wanted to do it using conditions, this is what you would need to do: 编辑:但是,如果您仍然想使用条件来执行此操作,则需要执行以下操作:
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
InstanceCount:
Type: Number
Conditions:
Launch10: !Equals [10, !Ref InstanceCount]
Launch9: !Or
- !Equals [9, !Ref InstanceCount]
- !Condition Launch10
Launch8: !Or
- !Equals [8, !Ref InstanceCount]
- !Condition Launch9
Launch7: !Or
- !Equals [7, !Ref InstanceCount]
- !Condition Launch8
Launch6: !Or
- !Equals [6, !Ref InstanceCount]
- !Condition Launch7
Launch5: !Or
- !Equals [5, !Ref InstanceCount]
- !Condition Launch6
Launch4: !Or
- !Equals [4, !Ref InstanceCount]
- !Condition Launch5
Launch3: !Or
- !Equals [3, !Ref InstanceCount]
- !Condition Launch4
Launch2: !Or
- !Equals [2, !Ref InstanceCount]
- !Condition Launch3
Launch1: !Or
- !Equals [1, !Ref InstanceCount]
- !Condition Launch2
Resources:
Bucket1:
Condition: Launch1
Type: AWS::S3::Bucket
Bucket2:
Condition: Launch2
Type: AWS::S3::Bucket
Bucket3:
Condition: Launch3
Type: AWS::S3::Bucket
Bucket4:
Condition: Launch4
Type: AWS::S3::Bucket
Bucket5:
Condition: Launch5
Type: AWS::S3::Bucket
Bucket6:
Condition: Launch6
Type: AWS::S3::Bucket
Bucket7:
Condition: Launch7
Type: AWS::S3::Bucket
Bucket8:
Condition: Launch8
Type: AWS::S3::Bucket
Bucket9:
Condition: Launch9
Type: AWS::S3::Bucket
Bucket10:
Condition: Launch10
Type: AWS::S3::Bucket
I've used bucket so it would be faster to test 我用过水桶,所以测试起来会更快
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.