2013-07-23 60 views
1

我使用這個CloudFormation腳本來創建一個Windows實例,並安裝Web Deploy爲什麼CloudFormation不會執行我的命令?

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

    "Description" : "Test.", 

    "Resources" : { 

    "InstanceSecurityGroup" : { 
     "Type" : "AWS::EC2::SecurityGroup", 
     "Properties" : { 
     "GroupDescription" : "Enable RDP", 
     "SecurityGroupIngress" : [ 
      {"IpProtocol" : "tcp", "FromPort" : "3389", "ToPort" : "3389", "CidrIp" : "0.0.0.0/0"} 
     ] 
     } 
    }, 

    "WindowsServer": { 
     "Type" : "AWS::EC2::Instance", 
     "Metadata" : { 
     "AWS::CloudFormation::Init" : { 
      "config" : { 
      "files" : { 
       "c:\\Packages\\WebDeploy_amd64_en-US.msi" : { 
       "source" : "http://download.microsoft.com/download/1/B/3/1B3F8377-CFE1-4B40-8402-AE1FC6A0A8C3/WebDeploy_amd64_en-US.msi" 
       } 
      } 
      }, 
      "commands" : { 
      "1-installwebdeploy" : { 
       "command" : "msiexec.exe /i c:\\Packages\\WebDeploy_amd64_en-US.msi ADDLOCAL=ALL /qn /norestart" 
      } 
      } 
     } 
     }, 

     "Properties": { 
     "InstanceType" : "m1.small", 
     "ImageId" : "ami-bbf2e1cf", 
     "SecurityGroups" : [ {"Ref" : "InstanceSecurityGroup"} ], 
     "KeyName" : "POP", 
     "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ 
      "<script>\n", 

      "cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" }, 
      " -r WindowsServer", 
      " --region ", { "Ref" : "AWS::Region" }, "\n", 

      "</script>" 
     ]]}} 
     } 
    } 
    } 
} 

MSI軟件包正確下載,但該命令不執行。實際上,cfn-init.log指出沒有指定任何命令:

2013-07-23 12:57:10,740 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.eu-west-1.amazonaws.com 
2013-07-23 12:57:10,740 [DEBUG] Describing resource WindowsServer in stack *** 
2013-07-23 12:57:14,079 [DEBUG] Creating Scheduled Task for cfn-init resume 
2013-07-23 12:57:14,220 [DEBUG] Scheduled Task created 
2013-07-23 12:57:14,328 [INFO] Running configSets: default 
2013-07-23 12:57:14,328 [INFO] Running configSet default 
2013-07-23 12:57:14,328 [INFO] Running config config 
2013-07-23 12:57:14,328 [DEBUG] No packages specified 
2013-07-23 12:57:14,328 [DEBUG] No groups specified 
2013-07-23 12:57:14,328 [DEBUG] No users specified 
2013-07-23 12:57:14,328 [DEBUG] No sources specified 
2013-07-23 12:57:14,328 [DEBUG] Parent directory c:\Packages does not exist, creating 
2013-07-23 12:57:14,328 [DEBUG] Writing content to c:\Packages\WebDeploy_amd64_en-US.msi 
2013-07-23 12:57:14,328 [DEBUG] Retrieving contents from http://download.microsoft.com/download/1/B/3/1B3F8377-CFE1-4B40-8402-AE1FC6A0A8C3/WebDeploy_amd64_en-US.msi 
2013-07-23 12:57:14,673 [DEBUG] No mode specified for c:\Packages\WebDeploy_amd64_en-US.msi 
2013-07-23 12:57:14,673 [WARNING] Unsupported OS for setting owner/group: nt 
2013-07-23 12:57:14,673 [DEBUG] No commands specified 
2013-07-23 12:57:14,673 [DEBUG] No services specified 
2013-07-23 12:57:14,673 [INFO] ConfigSets completed 
2013-07-23 12:57:14,734 [DEBUG] Deleting Scheduled Task for cfn-init resume 
2013-07-23 12:57:14,796 [DEBUG] Scheduled Task deleted 

這裏究竟發生了什麼?提前致謝。

回答

8

您的commands塊應嵌套在config塊內,此時它在層次結構中處於同一級別。

"AWS::CloudFormation::Init" : { 
     "config" : { 
     "files" : { 
      "c:\\Packages\\WebDeploy_amd64_en-US.msi" : { 
      "source" : "http://download.microsoft.com/download/1/B/3/1B3F8377-CFE1-4B40-8402-AE1FC6A0A8C3/WebDeploy_amd64_en-US.msi" 
      } 
     }, 
     "commands" : { 
      "1-installwebdeploy" : { 
      "command" : "msiexec.exe /i c:\\Packages\\WebDeploy_amd64_en-US.msi ADDLOCAL=ALL /qn /norestart" 
      } 
     } 
     }, 
    } 
+0

呃!謝謝羅伯特。 – Jonathan

相關問題