0
votes

This is my cloudFormation template.

Description: Create a variable number of EC2 instance resources.

Parameters:

  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

Error Message

Template contains errors.: Invalid template property or properties [InstanceType]

Can someone please help me to find why am I getting this error?

Thank you

1
You should post the complete properly formatted template. These type errors are formatting errors. - Rodrigo M
How do I do it? - Augusto Valdivia
I'm able to create a stack with the same template gist.github.com/sudharsans/0a9112e2afb337990388d78bef031454 - Sudharsan Sivasankaran

1 Answers

0
votes

If you observe closely, the indentation of the template was messed up at InstanceType after the InstanceCount. Fix it as mentioned below and you should be good to go.

  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 ]

Hope this helps.