A critical error in aws-alias.sh that can screw up everything

Hi Jeremy,

I looked through the alias scripts you provided and spotted a few syntax errors. These could lead your aliases to have different behaviors than what they claimed. People who have abnormal behaviors with the aliases might benefit from this post.

Here is one of them:

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"` && echo $instanceId'

Wow. That is a mouth full. Let’s zoom in and focus on where the problem lies.

aws ec2 describe-instances --filters "Name=instance-state-name,Values=stopped,Name=instance-type,Values=p2.xlarge"

Here Jeremy is trying to filter out only the instances that are stopped and have p2.xlarge as instance-type. However, the option values for aws ec2 describe-instances --filter are written in wrong syntax. Here is the correct syntax as specified in AWS-CLI refernce page of the command:

Name=string,Values=string,string ...

The most important thing to notice here is that we have to use space to separates different values of the same option, not comma. Look again at the option part of the command:

--filters "Name=instance-state-name,Values=stopped,Name=instance-type,Values=p2.xlarge"

It puts two option values in one pair of quotes and tries to separate them with comma. Though it appears to make sense, it is not the correct syntax. Here the filter option is simply ignored as bad syntax argument. So it is actually not filtering anything.

To make things a bit more clear, here is an reference page example that also uses two filters:

aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small,m1.medium" "Name=availability-zone,Values=us-west-2c"

Pay attention to how the two filters are in two separate pairs of quotes.

So, the problematic part of our original command should be rewritten as:

aws ec2 describe-instances --filters "Name=instance-state-name,Values=stopped" "Name=instance-type,Values=p2.xlarge"

Because of the special importance of space in syntax, we must not separate Name and Values with space.

Name=instance-state-name, Values=stopped

With only one extra space, the whole thing will blow up.

These adjustment should address some of the problems people might face while using the aliases.


@jeremy @rachel I have submitted a pool request to the fast.ai Github page to correct this error.