gpt4 book ai didi

amazon-web-services - Cloudformation 堆栈模板条件

转载 作者:行者123 更新时间:2023-12-03 07:37:19 25 4
gpt4 key购买 nike

如何创建带有条件子句的 Cloudformation 模板以创建 10 个实例作为参数。

我已将以下示例用于最多 5 个实例。但我怎样才能使用它超过5个呢?这取决于我们如何创建条件条款。

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]

您能帮我将此示例扩展到 10 个实例吗?

最佳答案

强烈建议您依赖 AutoScaling 组 ( AWS::AutoScaling::AutoScalingGroup )。这样您就可以使用 DesiredCapacity 属性引用实例计数。这样做还会给您带来很多其他好处。

编辑:但是如果您仍然想使用条件来执行此操作,那么您需要执行以下操作:

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

我使用了存储桶,因此测试速度会更快

关于amazon-web-services - Cloudformation 堆栈模板条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47945921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com