Created
          June 7, 2017 22:25 
        
      - 
      
 - 
        
Save glittershark/4cc347094e61394f638d9b1175234c47 to your computer and use it in GitHub Desktop.  
    SSH to an AWS server by name
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function instance_by_name() { | |
| aws ec2 describe-instances \ | |
| --filters "Name=tag:Name,Values=$1" \ | |
| | jq -r '.Reservations | map(.Instances) | flatten | map(.NetworkInterfaces) | flatten | map(.Association.PublicIp) | first' | |
| } | |
| SSH_KEY="/path/to/ssh/key" | |
| alias staging='ssh -i $SSH_KEY ec2-user@$(instance_by_name staging)' | |
| alias production='ssh -i $SSH_KEY ec2-user@$(instance_by_name production)' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
May want to add a comment distinguishing, e.g., "the production server" from "a production server", which hopefully won't matter much, but could cause some confusion if someone were expecting to find specific log output, etc.