I have a CloudFormation template that launches Windows instances with Java and Tomcat running as a service. I have to set the value of Maximum memory pool size for Tomcat in registry. I prepared a PowerShell command and it works fine from the command line. Then I tried 3 different ways of running them as a part of a CloudFormation template and none of those worked.
Neither Windows EventLog nor files in C:\Program Files\Amazon\Ec2ConfigService\Logs provided me any clue about why it had not worked.
1
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
--- some props removed ---,
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : [
"",
[
"<powershell>\n",
"Set-ItemProperty -Path \"HKLM:\\Software\\Wow6432Node\\Apache Software Foundation\\Procrun 2.0\\Tomcat8\\Parameters\\Java\" -Name JvmMx -Value 5000 \n",
"Restart-Service Tomcat8 \n",
"</powershell>"
]
]
}
}
}
}
2
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
--- some props removed ---,
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : [
"",
[
"<script>\n",
"PowerShell -Command \"& {Set-ItemProperty -Path 'HKLM:\\Software\\Wow6432Node\\Apache Software Foundation\\Procrun 2.0\\Tomcat8\\Parameters\\Java' -Name JvmMx -Value 5000}\" \n",
"PowerShell -Command \"& {Restart-Service Tomcat8}\" \n",
"</script>"
]
]
}
}
}
}
3
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
--- some props removed ---,
"UserData" : {
"Fn::Base64" : {
"Fn::Join" : [
"",
[
"<script>\n",
"cfn-init.exe -v -s ", {"Ref" : "AWS::StackId"}, " -r LaunchConfig --region ", {"Ref" : "AWS::Region"}, "\n",
"</script>"
]
]
}
}
},
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"commands" : {
"1-heapsize" : {
"command" : "PowerShell -Command \"& {Set-ItemProperty -Path 'HKLM:\\Software\\Wow6432Node\\Apache Software Foundation\\Procrun 2.0\\Tomcat8\\Parameters\\Java' -Name JvmMx -Value 5000}\""
},
"2-restart" : {
"command" : "PowerShell -Command \"& {Restart-Service Tomcat8}\""
}
}
}
}
}
}
