How to run Cloud Formation Init commands in PowerShell and not cmd?

0

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'"

1回答
1

The way that cfn-init works it will launch a cmd shell and then launch a powershell shell. I would recommend looking at AWS Systems Manager and using the integration between those two services that are available today. AWS Systems Manager gives you the ability to go directly into PowerShell.

https://aws.amazon.com/blogs/mt/using-state-manager-over-cfn-init-in-cloudformation-and-its-benefits/

https://www.youtube.com/watch?t=73&v=ckrwyijiJ7U&feature=youtu.be

https://aws.amazon.com/blogs/infrastructure-and-automation/using-aws-systems-manager-automation-and-aws-cloudformation-together/

profile pictureAWS
aaron_l
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ