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.
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}'