0

I am able to send simple commands to some of my Amazon ec2 instances. For example:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","mkdir -p test"]
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","sudo chmod 777 test"]

I can also echo text to a sample file:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","echo thisvalue = temp >> test/sample.txt"]

However, if I use a bracket as part of the command / text, for example:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands=["cd /home/ec2-user","echo [default] > test/sample.txt"]

I get the following error:

Error parsing parameter '--parameters': Expected: ',', received: '>' for input:

When the text is wrapped in brackets [] the issue is thrown. Therefore, the question boils down to: how am I able to pass 'special' characters through the aws ssm send-command function?

WX_M
  • 458
  • 4
  • 20

1 Answers1

1

The solution is:

aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids "${instanceid}" --parameters commands='["cd /home/ec2-user","echo [\default\] > test/sample.txt"]'

In other words, put single quotes around the command option and escape the brackets properly.

WX_M
  • 458
  • 4
  • 20
  • can you please tell how to re syntax the below command ```aws ssm send-command --instance-ids "i-0e4b1e415c969903f" --document-name "AWS-RunShellScript" --parameters commands="runuser -l pranayama -c 'cd /opt/laravel/pranayama && git branch'" ``` facing ```Error parsing parameter '--parameters': Expected: ',', received: ''' for input: commands=``` while executing the above command. can you please tell how can i escape the single quote inside the command argument – jayaprakash R Oct 14 '22 at 17:58