从控制台从Elastic Beanstalk实例之一获取公共DNS [英] obtain public DNS from one of the Elastic Beanstalk instances from the console
问题描述
我们想直接连接到我们的Elastic Beanstalk实例之一,因此我们需要知道它的public IP address
.
通常,我们从aws.console网站的EC2选项卡中获取实例的public IP
.这很麻烦,因为我们需要通过网络浏览几个页面...
我们已经从一台服务器中配置了eb
实用程序,因此我们可以使用eb list
轮询环境,或者使用eb status
检查状态.
我们如何使用eb
实用程序来获取环境实例的公共DNS?
或者还有其他方法可以获取此信息吗?
谢谢!
我不是EB CLI的用户.但是,您可以使用awscli
的1条命令来实现所需的功能.
首先安装并配置awscli
:
$ pip install awscli
$ aws configure
ElasticBeanstalk使用elasticbeanstalk:environment-name
标签自动标记属于ElasticBeanstalk环境的EC2实例.使用此信息,您可以筛选出具有特定elasticbeanstalk:environment-name
标记值的所有正在运行的实例.
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name"
以上命令将为您提供很长的JSON输出.您可以在其中轻松找到"PublicIpAddress"
,但是可以使用jq
之类的工具过滤此信息.因此,最终命令如下所示:
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name" | jq '.Reservations | .[] | .Instances | .[] | .PublicIpAddress'
尝试一下.
以下是有关awscli
命令使用的各种选项的更多信息:
看到ec2 describe-instances文档 >
更新2017年3月12日
jq
是不必要的,Linux命令行工具也是不必要的. awscli
支持--query
选项,该选项可用于使用 JMESPath(JSON查询语言)来查询您感兴趣的某些值.在这种情况下,您可以这样做:
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name" --query 'Reservations[].Instances[].PublicIpAddress' --output text
上面将打印纯IP地址,每行一个.
We like to connect directly to one of our instances of Elastic Beanstalk, thus we need to know its public IP address
.
We normally get the public IP
of the instance from the EC2 tab in the aws.console website. This is cumbersome because we need web browsing a couple of pages...
We have configured the eb
utility from one of our servers, so we can poll our environments with eb list
, or check the status with eb status
.
How can we user the eb
utility to obtain the public DNS of an instance of an environment?
Or is there any other way to obtain this information?
Thank you!
I'm not a user of EB CLI. However you could achieve what you want with 1 command using awscli
.
First install and configure awscli
:
$ pip install awscli
$ aws configure
ElasticBeanstalk automatically tags EC2 instances that are part of ElasticBeanstalk environment with elasticbeanstalk:environment-name
tag. Using this information you could filter out all your running instances that have a certain elasticbeanstalk:environment-name
tag value.
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name"
Above command will give you quite a long JSON output. You could simply find "PublicIpAddress"
in it, however you could filter this information with a tool like jq
. So final command would look something like:
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name" | jq '.Reservations | .[] | .Instances | .[] | .PublicIpAddress'
Try it.
Here is more information about various options for awscli
command used:
aws ec2 describe-instances docs
UPDATE 2017-03-12
jq
is unnecessary, Linux command line tools are unnecessary too. awscli
supports --query
option which can be used to query certain values you're interested in using JMESPath (JSON query language). In this case you would do:
$ aws ec2 describe-instances --filters "Name=tag:elasticbeanstalk:environment-name,Values=your-environment-name" --query 'Reservations[].Instances[].PublicIpAddress' --output text
Above will print plain IP addresses, one per line.
这篇关于从控制台从Elastic Beanstalk实例之一获取公共DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!