Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] What are the aliases used in The Effective AWS CLI User? #7

Closed
jason-riddle opened this issue Dec 5, 2016 · 4 comments
Closed

Comments

@jason-riddle
Copy link

In the following video (https://www.youtube.com/watch?v=Xc1dHtWa9-Q), there were three aliases that I thought were interesting.

aws authorize-my-ip
aws connect-ssh
aws auto-configure

What are the commands backing these aliases?

@kyleknap
Copy link
Contributor

kyleknap commented Dec 5, 2016

@jason-riddle

I want to add these to the repository. I just need to clean them up a bit before adding them. For the authorize-my-ip and connect-ssh, these are more or less how I defined them:

authorize-my-ip =
  !f() {
     my_cidr=<INSERT_CIDR_BLOCK_HERE>
     aws ec2 authorize-security-group-ingress --group-id "${1}" \
       --port 22 --protocol tcp --cidr "$my_cidr"
  }; f


connect-ssh =
  !f() {
    instance_output=$(aws ec2 describe-instances \
                        --instance-ids "${1}" \
                        --query Reservations[0].Instances[0])
    ssh_key_file=$(jp -u KeyName <<< "$instance_output")".pem"
    public_ip=$(jp -u PublicIpAddress <<< "$instance_output")
    if ! [ -f "$ssh_key_file" ];
    then
      echo "Error: Could not locate SSH key: "$ssh_key_file" in current" \
           "working direcory"
      exit 1
    fi
    if [ "$public_ip" == "null" ];
    then
      echo "EC2 Instance: "${1}" does not have a public IP address." \
           "Unable to connect with SSH."
      exit 1
    fi
    ssh -i "$ssh_key_file" ec2-user@"$public_ip"
  }; f

For the first one, I want to convert to a subcommand alias possibly and for the second alias I want to remove the dependency on jp and use a builtin UNIX command line tool instead in order to make it easier to use out of the box.

As to the auto-configure alias, it is shelling out to a python script that I have located on disk. I want to expose the script and the alias in the alias repository as well, but I need to clean it up a bit before I do so.

@jason-riddle
Copy link
Author

Sounds good. Thanks!

@ranman
Copy link

ranman commented Dec 26, 2016

could you do (to replace jp usage):

instance_output=($(aws ec2 describe-instances \
    --instance-ids "${1}" \
    --query 'Reservations[0].Instances[0].[KeyName,PublicIpAddress] | join(`" "`, @)' | tr -d '"'
))
ssh_key_file=$instance_output[1]".pem"
public_ip=$instance_output[2]

@ranman
Copy link

ranman commented Feb 2, 2017

hey @kyleknap does that combo of join and tr work for you? works for me locally but didn't test widely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants