我正在使用此CloudFormation脚本创建Windows实例并安装Web Deploy:
{
"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
这到底发生了什么?提前谢谢。
答案 0 :(得分:9)
您的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"
}
}
},
}