0x00 TL;DR

This article documents how to use AWS SSM to execute remote script files at EC2 instances.
There are two general methods:
1.Running Scripts from GitHub and Amazon S3
2.First upload the file to EC2 through SSM, and then use SSM to execute the command to run the uploaded script.

0x01 Running Scripts from GitHub

Use the following AWS Cli command

1
aws ssm send-command --document-name "AWS-RunRemoteScript" --instance-ids "i-0d781805630c8edc0" --parameters '{"sourceType":["GitHub"],"sourceInfo":["{\"owner\":\"omg2hei\", \"repository\":\"PowerShellDemo\", \"path\": \"/\"}"],"commandLine":["get-process.ps1"]}'

Then EC2 instance(Windows Server 2016) will be execute get-process.ps1.

0x02 First upload the file to EC2 through SSM, and then use SSM to execute the command to run the uploaded script

Step 1.Upload file to EC2 use SSM

1
aws ssm send-command --document-name "AWS-RunPowerShellScript" --parameters commands="Invoke-WebRequest http://52.80.67.123:8000/get-process.ps1 -OutFile c:\get-process.ps1" --instance-ids i-0d781805630c8edc0 --document-version "\$DEFAULT"

Step 2.use SSM to execute the command to run the uploaded script

1
aws ssm send-command --document-name "AWS-RunPowerShellScript" --parameters commands="c:\get-process.ps1" --instance-ids i-0d781805630c8edc0 --document-version "\$DEFAULT"

0x03 Reference

[1] Running Scripts from GitHub and Amazon S3 - https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-remote-scripts.html