2

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!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
arod
  • 13,481
  • 6
  • 31
  • 39

2 Answers2

4

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.

Michal Gasek
  • 6,173
  • 1
  • 18
  • 20
  • Ubuntu asks me to install the `jq`utility. However, I posted an answer to my dilemma which doesn't require this. Im giving you an upvote because `describe-instances` was the way to go, though I used `ec2-describe-instances` which is maybe an outdated API... – arod Dec 05 '16 at 21:50
  • You could just grep/awk/perl instead of using `jq` as well :) it's quite a convenient tool to work with JSON compared to standard toolkit. – Michal Gasek Dec 05 '16 at 21:54
  • @arod See updated answer for a really clean syntax without external tools. – Michal Gasek Mar 12 '17 at 22:41
0

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

arod
  • 13,481
  • 6
  • 31
  • 39