说明:创建可变数量的EC2实例资源。
参数:
InstanceCount:
Description: Number of EC2 instances (must be between 1 and 3).
Type: Number
Default: 1
MinValue: 1
MaxValue: 3
ConstraintDescription: Must be a number between 1 and 3.
Description: launch EC2 instances.
Type: AWS::EC2::Instance
InstanceType:
Description: Launch EC2 instances.
Type: String
Default: t2.micro
AllowedValues: [ t2.micro ]
Conditions:
Launch1: !Equals [1, 1]
Launch2: !Not [!Equals [1, !Ref InstanceCount]]
Launch3: !Or
- !Not [!Equals [1, !Ref InstanceCount]]
- !Not [!Equals [2, !Ref InstanceCount]]
**Resources:**
Instance1:
Condition: Launch1
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
AvailabilityZone: us-east-1a
ImageId: ami-a4c7edb2
Instance2:
Condition: Launch2
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
AvailabilityZone: us-east-1b
ImageId: ami-a4c7edb2
Instance3:
Condition: Launch3
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
AvailabilityZone: us-east-1c
ImageId: ami-a4c7edb2
模板包含错误。:无效的模板属性或属性[InstanceType]
谢谢
答案 0 :(得分:0)
如果您仔细观察,模板的缩进在InstanceType
之后的InstanceCount
处被弄乱了。如下所述修复它,您应该一切顺利。
InstanceCount:
Description: Number of EC2 instances (must be between 1 and 3).
Type: Number
Default: 1
MinValue: 1
MaxValue: 3
ConstraintDescription: Must be a number between 1 and 3.
Description: launch EC2 instances.
Type: AWS::EC2::Instance
InstanceType:
Description: Launch EC2 instances.
Type: String
Default: t2.micro
AllowedValues: [ t2.micro ]
希望这会有所帮助。