0
votes

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?

1
May be try to escape special characters by using a backslash? - Asdfg
If I do: [\default this works but only gives me [default (without the closing bracket). But if I do [\default]\ it will not work at all. - WX_M
try \[default\] - Asdfg
same issue as original post. - WX_M

1 Answers

0
votes

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.