是否有使用Name标签连接到EC2实例的简便方法? [英] Is there an easy way to connect to EC2 instances using their Name tag?
问题描述
我们的团队正在AWS上工作,那里有很多实例,我们会不断添加和删除它们。每个实例都有一个逻辑名称,这有助于我们知道它的功能以及找到它的位置。
但是,当我们要连接到一个主机时,要么需要一直更新〜/ .ssh / config
文件,要么请转到Web控制台。 ,按实例名称查找实例,复制其IP,然后我们才能使用以下实例来运行它:
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
我在徘徊是否有一种更简单的方法,可以在其中指定计算机名称,而EC2可以完成其余的工作?
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?
ssh-aws my-machine-name
推荐答案
我写了一个小bash脚本,它使用 aws-cli
(感谢< a href = https://stackoverflow.com/users/228514/ryan-parman> @Ryan Parman ),以从计算机名称中找到正确的计算机IP和PEM:
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:
要使用它,只需调用
sash <machine-name>
我还为它添加了更多功能,例如 upup
,下载
和Multiplex连接...
I've also added more features to it like upload
, download
, and multiplex connect...
这篇关于是否有使用Name标签连接到EC2实例的简便方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!