TIM02144
TIM02144

Reputation: 615

AWS CloudFormation Template (JSON) to Create EC2 - Unexpected Error

Getting started testing Cloud Formation templates to create EC2 instances, using JSON format, getting an error "Every Parameters object must contain a Type member." I cannot find a solution on the web.

I've searched this error and the only solution I found was to add "Type": "String" to the template but that is already there.

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "EC2 CloudFormation Template - Version 1.0",
    "Metadata": {},
    "Parameters": {
      "InstanceType": {
        "Description": "EC2 instance type",
        "Type": "String",
        "Default": "t2.small",
        "AllowedValues": [
          "t1.micro",
          "t2.nano",
          "t2.micro",
          "t2.small",
          "t2.medium",
          "t2.large",
        ],
        "ConstraintDescription": "must be a valid EC2 instance type."
    },
    "Mappings": {

    },
    "Conditions": {

    },
    "Resources": {
      "EOTSS_EC2": {
          "Type": "AWS::EC2::Instance",
          "Properties": {
              "DisableApiTermination": "false",
              "ImageId": "ami-06bee8e1000e44ca4",
              "InstanceType": { "Ref": "InstanceType" },
              "Monitoring": "true",
              "Tags": [
                  {
                      "Key": "Name",
                      "Value": "test"
                  }
              ]
            }
          }
      },
      "Outputs": {

      }
    }
}

The error I get when I launch this as a new stack is "Template format error: Every Parameters object must contain a Type member."

Upvotes: 0

Views: 756

Answers (1)

Pedro Arantes
Pedro Arantes

Reputation: 5379

The problem is that your template isn't well nested: Outputs should be outside EOTSS_EC2 and Resources, in other words, should be at the same level of AWSTemplateFormatVersion, Description, Metadata, Parameters, Mappings, Conditions and Resources.

{  
   "AWSTemplateFormatVersion":"2010-09-09",
   "Description":"EC2 CloudFormation Template - Version 1.0",
   "Metadata":{  

   },
   "Parameters":{  
      "InstanceType":{  
         "Description":"EC2 instance type",
         "Type":"String",
         "Default":"t2.small",
         "AllowedValues":[  
            "t1.micro",
            "t2.nano",
            "t2.micro",
            "t2.small",
            "t2.medium",
            "t2.large"
         ],
         "ConstraintDescription":"must be a valid EC2 instance type."
      }
   },
   "Mappings":{  

   },
   "Conditions":{  

   },
   "Resources":{  
      "EOTSS_EC2":{  
         "Type":"AWS::EC2::Instance",
         "Properties":{  
            "DisableApiTermination":"false",
            "ImageId":"ami-06bee8e1000e44ca4",
            "InstanceType":{  
               "Ref":"InstanceType"
            },
            "Monitoring":"true",
            "Tags":[  
               {  
                  "Key":"Name",
                  "Value":"test"
               }
            ]
         }
      }
   },
   "Outputs":{  

   }
}

Upvotes: 2

Related Questions