Rodrigo Murillo
Rodrigo Murillo

Reputation: 13648

How do I properly reference a Powershell script from an AWS SSM document?

The Amazon EC2 Simple Systems Manager documentation for the runPowerShellScript API call show how to specify a path to a PowerShell script for execution.

I have tried to specify the full script path as indicated in the documentation:

"runCommand":"c:\tools\GetTools.ps1",

but I get a syntax error when creating the document, even though the JSON document is correct:

aws ssm create-document --content file://myssmdocument.json --name "runPSScript"

A client error (InvalidDocumentContent) occurred when calling the CreateDocument operation: JSON not well-formed. at Line: 12, Column: 29

What is the correct syntax?

Upvotes: 1

Views: 2300

Answers (1)

Rodrigo Murillo
Rodrigo Murillo

Reputation: 13648

The AWS documentation for the RunCommand parameter states:

"Specify the command to run or the path to an existing script on the instance."

It appears the parameter does not actually accept a path. It will generate an error as above if you provide one.

The work around is to use only the script name in the runCommand parameter, and specify the full path in the WorkingDirectory

      "runCommand":"GetTools.ps1",
      "workingDirectory": "c:\tools"

This format will allow the ssm create-document command to run successfully.

Upvotes: 1

Related Questions