5

Knowing how to set custom environment variables on AWS Elastic Beanstalk, I wonder if there is a default environment property for the name of the environment. If there is, where is this described in the documentation?

For example, suppose my EB environment is named "my_env," is there some kind of default environment property like e.g. "AWS_EB_ENV_NAME" that I can access to obtain this name?

djvg
  • 11,722
  • 5
  • 72
  • 103
  • 1
    Based on the answer by Tom Paulus, the simplest approach is still to set an environment property with the following value `\`{ "Ref" : "AWSEBEnvironmentName" }\``, either using the EB management console, or using `option_settings: ...` in an `.ebextensions` config file. – djvg Oct 26 '18 at 07:05

1 Answers1

3

You can either set the environment variable yourself during the instance creation via an ebextension or the Web Console during environment creation. Described here: How do you pass custom environment variable on Amazon Elastic Beanstalk (AWS EBS)?

Or you can use a combination of requests to the Meta-Data server, which sits between your EC2 instance and the netwrok, and the AWS EB API; as described in: https://serverfault.com/questions/630075/is-it-possible-to-get-metadata-about-the-elastic-beanstalk-environment-from-the

Tom Paulus
  • 125
  • 7
  • 4
    Thanks. So the answer is "No?" – djvg Jun 15 '17 at 10:08
  • 1
    Did you read the second link that @Tom-Paulus provided? It is completely possible to do what you want with a combination of `http://169.254.169.254/latest/meta-data/instance-id`, `aws elasticbeanstalk describe-environments`, and `aws elasticbeanstalk describe-environment-resources`. – Brian Jun 15 '17 at 14:09
  • @Brian, yes I did read the second link, and I completely understand that it is completely possible using that approach. However, my question was whether there exists a default environment variable for this purpose. It seems there does not. – djvg Jun 16 '17 at 06:31
  • 1
    It'd be much simpler to set an environment variable in an ebextension with the output of this command: `/opt/elasticbeanstalk/bin/get-config container -k environment_name` – Matt Nov 11 '19 at 21:49