Cloudformation模板错误 - 模板验证错误:模板格式错误:每个Mappings成员类型必须是地图

问题描述:

我有一个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

我和yaml模板有同样的问题。 它看起来像只有2级映射在模板的支持,所以你需要酌情添加另一个级别,例如,

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