Bruno
Bruno

Reputation: 497

AWS SSM Send Command: Parameters argument not going through

I am trying to execute a PowerShell Script on a Windows EC2 Instance. The Powershell Script works (I RDP'd and executed it) but when I try to execute it using Boto3 SSM, it does not allow me to execute it with a parameter.

I am fairly positive this is a simple lack of clarity in the documentation or I am just making a fairly dumb mistake.

I have executed other Powershell scripts into the target instance but it seems like I can't get a powershell script that requires a parameter to work.

My Powershell script starts with:

      param(
      [string]$roleToRegister
      )

and in my Lambda I call it using:

result = ssm.send_command(DocumentName="registerxx", InstanceIds=instances, 
Parameters={'roleToRegister': ['myRole'] })

Currently I am receiving:

"An error occurred (InvalidParameters) when calling the SendCommand operation:

I have also tried defining the parameters dict as :

{
'$roleToRegister' : ['myRole']
}

Any ideas would be great. Thank you.

Link to documentation: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.send_command

Upvotes: 1

Views: 4811

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

Before sending the command with parameters. Ensure that the command document declares the parameters.

See schema definition: https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-plugins.html#top-level

For example:

{
  "schemaVersion": "2.2",
  "description": "Registers XX using the aws:runShellScript plugin.",
  "parameters": {
    "roleToRegister": {
      "type": "StringList",
      "description": "(Required) This is a required parameter that will be use to determine the roles to register.",
      "minItems": 1
    }
  },
  "mainSteps": [
    {
      "action": "aws:runPowerShellScript",
      "name": "RegisterXX",
      "inputs": {
        "timeoutSeconds": 60,
        "runCommand": [
          "$roles = '{{ rolesToRegister }}'",
          "Write-Host $roles"
        ]
      }
    }
  ]
}

Upvotes: 1

Related Questions