Home > database >  Escaping characters in AWS SSM command
Escaping characters in AWS SSM command

Time:01-13

I can't get my escape characters correct for an AWS SSM command with double quotes inside. Here's the last attempt:

aws ssm send-command --instance-ids "i-012345678" --document-name "AWS-RunShellScript" --query "Command.CommandId"  --output text --parameters commands='["sudo su","cd /opt/cassandra/bin","cqlsh -e \"select * from system_schema.keyspaces;"\"]'

Essentially it's the last command, the double quotes around the cqlsh command that I can't escape from erroring. Have tried to store it in variable and echo but neither works. Also looked at answers below.

aws ssm send-command not working with special characters Send multiple lines of script to EC2 instance from PowerShell SSM cmdlets

CodePudding user response:

Per the documentation,

You do not need to escape double quotation marks embedded in the JSON string, as they are being treated literally.

Could you instead try the below?

aws ssm send-command \
--instance-ids "i-012345678" \
--document-name "AWS-RunShellScript" \
--query "Command.CommandId" \
--output text \
--parameters commands='[{"sudo su","/opt/cassandra/bin/cqlsh -e \"SELECT * FROM system_schema.keyspaces;\""}]'
  • Related