Skip to content

Instantly share code, notes, and snippets.

@leonidlm
Created July 1, 2015 12:03
Show Gist options
  • Save leonidlm/c2d14298d1a54a63881b to your computer and use it in GitHub Desktop.
Save leonidlm/c2d14298d1a54a63881b to your computer and use it in GitHub Desktop.
ssh-core.sh
#!/bin/bash
ip_from_instance() {
echo $(aws ec2 describe-instances \
--filters \
"{\"Name\":\"tag:Name\", \"Values\":[\"$1\"]}" \
"{\"Name\":\"instance-state-name\", \"Values\":[\"running\"]}" \
--query='Reservations[0].Instances[0].PublicIpAddress' | tr -d '"')
}
ssh-core() {
local instance_name="$1"
# Determine if the instance is in staging or production
case "$instance_name" in
*staging*)
key="ansible-staging.pem"
;;
*production*)
key="ansible-production.pem"
;;
*)
echo "Unknown instance name '$instance_name'"
exit 1
esac
ssh-add "/home/leonid/.ssh/$key"
ssh -A core@$(ip_from_instance "$instance_name")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment