Search code examples
sshamazon-ec2

Is there an easy way to connect to EC2 instances using their Name tag?


Our team is working on AWS, where we have lots of instances, which we keep adding and removing. Each instance has a logical name, which helps us know what it does as well as finding it. When we want to connect to one, though, we either need to update the ~/.ssh/config file all the time, or go to the web console, find the instance by its name, copying its IP and only then we can run it using:

ssh -i ~/.aws/my-pem-file.pem ubuntu@ec2-111-111-111-111.compute-1.amazonaws.com

I was wandering whether there is an easier way to do it, where you could specify the machine name, and EC2 would do the rest?

Something like

ssh-aws my-machine-name

Solution

  • I wrote a little bash script which uses aws-cli (thanks @Ryan Parman) to find the correct machine IP and PEM from the machine name:

    http://sash.agassi.co.il/

    To use it simply call

    sash <machine-name>
    

    I've also added more features to it like upload, download, and multiplex connect...