I'm bootstrapping a EC2 Windows 2016 instance via CloudFormation Metadata using cfn-init.
My goal is to create a .properties file on the instance, where each property line must come on a separate line. I have tried with both the approaches below. But everytime, instead of creating multiple lines, all the lines are concatenate.
Sample file I'm trying to create:
INSTALLER_UI=SILENT
CONTROLLER_PORT=\"8080\"
LISTEN_PORT=\"7070\"
But the file that gets created every time:
INSTALLER_UI=SILENTCONTROLLER_PORT="8130"LISTEN_PORT=\"7913\"
Cloudformation template code using !Sub
Metadata:
AWS::CloudFormation::Init:
config
- 01InstallMyAgent
01_InstallMyAgent:
files:
"D:\\installers\\Agent\\agent.properties":
content: !Sub |+
INSTALLER_UI=SILENT
CONTROLLER_PORT="8130"
LISTEN_PORT=\"7913\"
Cloudformation template code using !Join
Metadata:
AWS::CloudFormation::Init:
config
- 01InstallMyAgent
01_InstallMyAgent:
files:
"D:\\installers\\Agent\\agent.properties":
content: !Join ["\n",
[
"INSTALLER_UI=SILENT",
'CONTROLLER_PORT=\"8130\"',
'LISTEN_PORT=\"7913\"',
],
]
I've also tried join with "" as the delimiter and appended "\n" to the end of each line but absolutely no luck.
Question 2: Also pls. suggest a way to test the above code locally somehow. Right now I only have to execute the stack, RDP into the EC2 instance and check the file contents, only to see that my small change has failed. Any way to test this out without having to actually create the instance. Thanks...
Question 3: Are there any repository of Windows cloudformation samples. Because that is very hard to find. Almost all the samples I find are for linux.
Thanks a lot !!