Aliases in aws-alias.sh two sets of quotes around instance id

When I run aws-start, I get this error:

An error occurred (InvalidInstanceID.Malformed) when calling the StartInstances operation: Invalid id: "“i-0972dcf72eaa51586"” (expecting “i-…”)

The value of the exported environment variable from aws-get-p2 is quoted, which may be the problem.

echo $instanceId
"i-0972dcf72eaa51586"

–Peter G

I had the same problem. When I ran “aws configure” I forgot to set output type to “text”. Fixing this got rid of the quotes.

How you got rid of the quotes?

While switching output type from aws configure will achieve this, you could also get rid of the quotes by piping the output from the aws cli through tr:

For example:

alias aws-get-p2='export instanceId=`aws ec2 describe-instances --filters "Name=instance-state-name,Values=stopped,Name=instance-type,Values=p2.xlarge" --query "Reservations[0].Instances[0].InstanceId"  | tr -d \"\"\"` && echo $instanceId'
1 Like