In Coudformation templates, there is a section to specfiy commands like below. Under fullServer
I am running the command install
. However, when I look at the logs after cfn has run on the server, it shows
2022-10-20 13:41:25,780 [INFO] Command install succeeded
2022-10-20 13:41:25,796 [DEBUG] Command install output: $MAGIC
This is because the $Magic
is how to declare and use variables in powershell where as cmd needs the set
keyword. I would expect the output of this command to be Command install output: I am from the full server env
.
"AWS::CloudFormation::Init": {
"configSets": {
"downloadS3Data": ["downloadS3"],
"Full": [{"ConfigSet": "downloadS3Data"}, "fullServer"],
"default": [ {"ConfigSet": "Full"}],
"App": [{"ConfigSet": "downloadS3Data"}, "appServer"],
"Interface": [{"ConfigSet": "downloadS3Data"}, "interfaceServer"],
"Notification": [{"ConfigSet": "downloadS3Data"}, "notificationServer"]
},
"downloadS3": {
"files": {
"C:\\ccw_downloads\\test.txt": {
"source": "https://ccw-to-rds-poc-1.s3.us-east-2.amazonaws.com/test.txt",
"authentication": "S3AccessCreds"
}
}
},
"fullServer": {
"commands": {
"install": {
"command": "echo $MAGIC",
"env": {"MAGIC": "I am from the full server env"},
"cwd": "C:\\ccw_downloads",
"waitAfterCompletion": 120
}
}
}
}
I would like to run the command with PowerShell and not cmd. Is there a way to specify that like I can with User Data?
I know that I could append PowerShell -Command
to the beginning, making cmd call PowerShell and pass args. However, that would not allow me to use the enviornment variable MAGIC
. For example "command": "Powershell -Command 'echo $magic'"