bashamazon-web-servicesaws-ssmruncommand

Expected: ',', received: ']' AWS SSM RunShellScript


I want to update many instances, so I have made a script with this command:

aws ssm send-command --instance-ids "$y" --document-name AWS-RunShellScript --parameters commands='yum -y update; needs-restarting -r; if \[ $? -eq 1 \]; then exit 194' --cloud-watch-output-config "CloudWatchOutputEnabled=true"

Instead of running the command on the machines specified by $y, it says: Error parsing parameter '--parameters': Expected: ',', received: ']' for input: commands=yum -y update; needs-restarting -r; if \[ 252 -eq 1 \]; then exit 194; else exit 0; fi

Note that the $? is referenced as 252 for some reason.


Solution

  • Try putting double quotes around the value for --parameters:

    aws ssm send-command --instance-ids "$y" --document-name AWS-RunShellScript --parameters "commands='yum -y update; needs-restarting -r; if \[ $? -eq 1 \]; then exit 194'" --cloud-watch-output-config "CloudWatchOutputEnabled=true"
    

    See the examples in the aws-cli reference.