Skip to content

Instantly share code, notes, and snippets.

@bsingr
Last active August 10, 2017 06:49
Show Gist options
  • Save bsingr/0849794d823e727f904948092b9fdbd7 to your computer and use it in GitHub Desktop.
Save bsingr/0849794d823e727f904948092b9fdbd7 to your computer and use it in GitHub Desktop.
SSH into AWS EC2 Instance by tag "Name"

SSH into AWS EC2 Instances by tag "Name"

Requirements

Installation

curl https://gist.githubusercontent.com/bsingr/0849794d823e727f904948092b9fdbd7/raw/1dad0590de07d0f302377000f4673b18355dbc59/awssh.sh > /usr/local/bin/awssh
chmod +x /usr/local/bin/awssh

Usage

awssh <aws-profile-name> <value-of-ec2-instance-tag-Name>

E.g.

awssh my-profile my-web-01

#!/bin/sh
# Usage
# $ awssh <aws-profile-name> <value-of-ec2-instance-tag-Name>
# e.g. $ awssh my-profile my-web-01
ssh $(aws --profile $1 ec2 describe-instances --query "Reservations[].Instances[].[PrivateIpAddress]" --filter "Name=tag:Name,Values=$2" | jq -r .[][0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment