Last active
February 11, 2024 01:26
-
-
Save atheiman/d51b323a8d2fb33139e3950b46f2a99a to your computer and use it in GitHub Desktop.
SSM Command document to run a Powershell command on Windows instances and a shell command on Linux instances. The commands are hard-coded, but could be moved to input parameters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SSM Command document to run a Powershell command on Windows instances and a shell command | |
# on Linux instances. The commands are hard-coded, but could be moved to input parameters. | |
schemaVersion: "2.2" | |
description: Run a PowerShell command on Windows instances and a shell command on Linux instances | |
mainSteps: | |
- precondition: | |
StringEquals: [platformType, Windows] | |
action: "aws:runPowerShellScript" | |
name: runPowerShellScript | |
inputs: | |
workingDirectory: C:\Windows\Temp\ | |
runCommand: | |
- $ErrorActionPreference = "Stop" | |
- Write-Output "Start script (PowerShell $($PSVersionTable.PSVersion))" | |
- '"File contents from Command document!" | Out-File -FilePath C:\Windows\Temp\file.txt' | |
- Write-Output "Complete" | |
- precondition: | |
StringEquals: [platformType, Linux] | |
action: "aws:runShellScript" | |
name: runShellScript | |
inputs: | |
workingDirectory: /tmp | |
runCommand: | |
- set -e | |
- echo "Start script ($SHELL)" | |
- echo "File contents from Command document!" > /tmp/file.txt | |
- echo "Complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment