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
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠