簡體   English   中英

AWS CloudFormation模板(JSON)創建EC2-意外錯誤

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

開始測試Cloud Formation模板以使用JSON格式創建EC2實例,並收到錯誤消息“每個參數對象必須包含Type成員”。 我無法在網絡上找到解決方案。

我搜索了此錯誤,發現的唯一解決方案是在模板中添加“ 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": {

      }
    }
}

當我將其作為新堆棧啟動時遇到的錯誤是“模板格式錯誤:每個Parameters對象都必須包含Type成員。”

問題是您的模板嵌套不好: Outputs應該在EOTSS_EC2Resources之外,換句話說,應該在AWSTemplateFormatVersionDescriptionMetadataParametersMappingsConditionsResources的同一級別。

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

   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM