obtain public DNS from one of the Elastic Beanstalk instances from the console

ⅰ亾dé卋堺 提交于 2019-12-11 03:34:16

问题


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!


回答1:


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.




回答2:


This is a quick and dirty way:

ec2-describe-instances $(eb status -v | grep InService | cut -d":" -f1 | awk '{print $1}') | grep INSTANCE | awk '{print $4}'



来源:https://stackoverflow.com/questions/40982686/obtain-public-dns-from-one-of-the-elastic-beanstalk-instances-from-the-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!