如何发现同一EC2安全组中的所有实例 [英] How to discover all instances in the same ec2 security group

查看:98
本文介绍了如何发现同一EC2安全组中的所有实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,不可能将八卦协议用作ec2上的节点发现机制.

Unfortunately it is not possible to use the gossip protocol as a node discovery mechanism on ec2.

因此,我需要找到一种方法来列出位于同一安全组中的节点的所有私有IP地址.我想通过自动发现机制来做到这一点.

So I need to find a way to list all private ip addresses of the nodes which are located in the same security group. I want to do this over an auto discovery mechanism.

更多详细信息:

我有多个ec2实例,它们正在运行所有相同的docker容器,但docker容器未安装aws-cli.因此,我正在寻找一种方法来检测具有现有注册表或至少没有aws-cli作为依赖项的其他实例.在容器中运行的应用程序需要其他容器的ip相互连接.

I have multiple ec2 instances which are running all the same docker container but the docker container has no aws-cli installed. Therefore I am looking for a way to detect the other instances with an existing registry or at least without aws-cli as dependency. The application running in the container needs the ips of the other containers to connect to each other.

推荐答案

使用describe-instancesfilter组名或组ID.

来自:描述实例

  • instance.group-id-实例的安全组的ID.
  • instance.group-name-实例的安全组的名称.

使用安全组ID

aws ec2 describe-instances --filters "Name=instance.group-id,Values=sg-082b1234" --query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text

输出

10.1.1.24
10.1.1.49

使用安全组名称

aws ec2 describe-instances --filters "Name=instance.group-name,Values=default" --query 'Reservations[*].Instances[*].[PrivateIpAddress]' --output text

输出

10.1.1.24
10.1.1.49

这篇关于如何发现同一EC2安全组中的所有实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆