Misiur
Misiur

Reputation: 5297

Is it possible to get elastic beanstalk address from within its EC2 instance?

As in title. I have elastic beanstalk instances set up as "load balanced, auto scaling", and would like to get beanstalk address from inside of its autocreated EC2 instances.

Is is possible?

Upvotes: 0

Views: 210

Answers (1)

Matt Houser
Matt Houser

Reputation: 36103

The Elastic Beanstalk URL is an alias to the Elastic Load Balancer's URL.

  1. From the EC2 instance, you can call into the EC2 metadata to get the instance's ID.
  2. Get the list of Elastic Load Balancers using elasticloadbalancing:DescribeLoadBalancers.
  3. From that list, find the load balancer(s) that include your EC2 instance ID in the Instances property.
  4. The DNSName of the matching ELB(s) will be the DNS name of your load balancer.

Note: Above I allude to the fact that your EC2 instance may be attached to multiple load balancers. In reality, Elastic Beanstalk will only attach your EC2 instance to a single ELB, but for "completeness", you could allow for the possibility of multiple ELBs.

Upvotes: 3

Related Questions