2017-10-19 51 views
-2

我有一個cloudformation模板。Cloudformation模板錯誤 - 模板驗證錯誤:模板格式錯誤:每個Mappings成員類型必須是地圖

它應該創建一個EC2實例,更改Adminstrator密碼並重命名服務器。

我將幾個參數傳遞給堆棧模板。當我運行它時,它會給出「模板格式錯誤:每個映射成員類型必須是一個映射」。

我確保我在模板中提到的任何內容都位於「映射」部分。不知道爲什麼我得到這個錯誤。

任何建議是非常有幫助的。

{ 
    "AWSTemplateFormatVersion": "2010-09-09", 

    "Parameters": { 

"LocalAdminPassword" : 
{ 
    "Type": "String", 
    "NoEcho" : "true", 
    "Description": "Password for the local server administrator account." 
    } 
}, 

"Mappings": { 

"EnvironmentTypeName" : 
{ 
    "PlatformName" : {"Dev" : "D", "Test" : "T", "Prod" : "P"} 
}, 
"QRMEnvironmentType" : 
{ 
    "Description" : "QRM Dev, test, or Prod Platform", 
    "Type"   : "String", 
    "AllowedValues" : ["Dev", "Test", "Prod"], 
    "Default" : "Dev", 
    "ConstraintDescription" : "must be either Dev, test, or Prod" 
}, 
"QRMAvailabilityZoneIndex" : 
{ 
    "Description" : "QRM Platform AZ letter A,B, or C for Dev, Test, or Prod", 
    "Type"   : "String", 
    "AllowedValues" : ["A", "B", "C"], 
    "Default" : "A", 
    "ConstraintDescription" : "Must be a letter of the AZ in the specified Region" 
    } 
}, 

"Resources": { 
     "MyInstance": { 
     "Type": "AWS::EC2::Instance", 
     "Metadata" : { 
      "AWS::CloudFormation::Init" : { 
     "config" : { 
      "files" : { 
      "c:\\cfn\\cfn-hup.conf" : { 
       "content" : { "Fn::Join" : ["", [ 
       "[main]\n", 
       "stack=", { "Ref" : "AWS::StackId" }, "\n", 
       "region=", { "Ref" : "AWS::Region" }, "\n" 
       ]]} 
      }, 
      "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : { 
       "content": { "Fn::Join" : ["", [ 
       "[cfn-auto-reloader-hook]\n", 
       "triggers=post.update\n", 
      "path=Resources.MyInstance.Metadata.AWS::CloudFormation::Init\n", 
       "action=cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" }, 
               " -r MyInstance", 
               " --region ", { "Ref" : "AWS::Region" }, "\n" 
       ]]} 
      }, 
      "c:\\scripts\\test.ps1" : { 
       "content": { "Fn::Join" : ["", [ 
       "Write-Host Hello World!\n" 
       ]]} 
      } 
      }, 
      "commands" : { 

      "1-run-script" : 
      { 
       "command" : 
        { 
         "Fn::Join" : 
         [ 
         "", 
         [ 
          "Powershell.exe ([adsi]\\\"WinNT://$env:computername/Administrator\\\").SetPassword('",{ "Ref": "LocalAdminPassword"},"')" 
         ] 
         ] 
        } 
      }, 
      "02-rename-server" : 
        { 
        "command" : 
        { 
         "Fn::Join" : 
         [ 
         "", 
         [ 
          "powershell.exe Rename-Computer -NewName ", {"Fn::Join" : [ "",[ "AW", {"Fn::FindInMap" : [ "EnvironmentTypeName", "PlatformName", {"Ref" : "QRMEnvironmentType"} ]},"W",{"Ref": "QRMAvailabilityZoneIndex"},"QRMHEAD"]] } ," -force -restart" 
         ] 
         ] 
        }, 
        "WaitAfterCompletion" : "forever" 
        },     
       "3-run-script" : { 
        "command" : { "Fn::Join" : [ "", [ 
         "Powershell.exe Set-ExecutionPolicy Unrestricted -force \n", 
         "Powershell.exe C:\\scripts\\test.ps1 \n", 
         "Powershell.exe Start-Sleep -s 60; . C:\\PowershellScripts\\WindowsServiceManager.ps1;StopWindowsService Dnscache" , "\n" 
         ]]}} 
       }, 
      "services": { 
       "windows": { 
        "cfn-hup": { 
          "enabled": "true", 
          "ensureRunning": "true", 
          "files": ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"] 
                  } 
           } 
              } 
    }         
          } 
    }, 
"Properties": { 
    "DisableApiTermination": "FALSE", 
    "ImageId": "ami-3723c04f", 
    "InstanceType": "t2.micro", 
    "KeyName": "EC2Instances", 
    "Monitoring": "false", 
    "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ 
    "<script>\n", 
    "cfn-init.exe -v -s ", { "Ref" : "AWS::StackName" }, 
    " -r MyInstance", 
    " --region ", { "Ref" : "AWS::Region" }, "\n", 

    "cfn-signal.exe -e 0 ", { "Fn::Base64" : { "Ref" : "WindowsServerWaitHandle" }}, "\n", 

    "</script>\n" 
    ]]}}, 
    "Tags": [ 
    { 
     "Key": "Name", 
     "Value": "MyEC2Instance" 
    } 
    ], 

    } 
    , 
    "WindowsServerWaitHandle": { 
     "Type": "AWS::CloudFormation::WaitConditionHandle" 
    }, 
    "WindowsServerWaitCondition": { 
      "Type": "AWS::CloudFormation::WaitCondition", 
      "DependsOn": "MyInstance", 
     "Properties": { 
    "Handle": { "Ref": "WindowsServerWaitHandle" }, 
    "Timeout": "1800" 
    } 
    }   
} 
} 
+0

這怎麼不是一個有效的問題嗎?這個論壇是瘋了。請解釋爲什麼我的問題被拒絕投票? – jason

回答

0

我和yaml模板有同樣的問題。 它看起來像只有2級映射在模板的支持,所以你需要酌情添加另一個級別,例如,

... 
"QRMEnvironmentType" : 
{ 
    "Description" : {"Value": "QRM Dev, test, or Prod Platform"}, 
    "Type"   : {"Value": "String"}, 
    ... 
} 
...