更新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 configureElasticBeanstalk 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 docsUPDATE 2017-03-12jq 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 textAbove will print plain IP addresses, one per line. 这篇关于从控制台从Elastic Beanstalk实例之一获取公共DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 17:22