【问题标题】:AWS CloudFormation Template (JSON) to Create EC2 - Unexpected Error用于创建 EC2 的 AWS CloudFormation 模板 (JSON) - 意外错误
【发布时间】:2019-10-25 02:38:41
【问题描述】:

开始测试 Cloud Formation 模板以使用 JSON 格式创建 EC2 实例,收到错误“每个参数对象都必须包含一个类型成员”。我在网上找不到解决方案。

我已经搜索过这个错误,我发现的唯一解决方案是将“Type”:“String”添加到模板中,但它已经存在了。

{
    "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": {

      }
    }
}

当我将它作为新堆栈启动时,我得到的错误是“模板格式错误:每个参数对象都必须包含一个类型成员。”

【问题讨论】:

    标签: json amazon-ec2 amazon-cloudformation


    【解决方案1】:

    问题是你的模板没有很好地嵌套:Outputs 应该在EOTSS_EC2Resources 之外,换句话说,应该在AWSTemplateFormatVersionDescription、@987654326 的同一级别@、ParametersMappingsConditionsResources

    {  
       "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":{  
    
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 2020-08-03
      • 2019-09-22
      • 2018-10-12
      • 1970-01-01
      • 2019-07-24
      • 2021-12-08
      相关资源
      最近更新 更多