3

I've set some properties with their values in Elastic Beanstalk on Amazon. An example is: enter image description here

I have a .NET application which I will deploy on an EC2 Windows server with IIS. The .NET project contains an .ebextensions folder in which we include .config files to do further configurations.

Now is my question. Am I able to read the value of a property (so read "root" from property DB.Username" inside a .config file in the .ebextensions folder?

I tried something like this but it seems that a property of Elastic Beanstalk isn't a real Windows environment variable

commands:
  010-01-test:
    command: echo %DB.Username%

I know those variables are also used in web.config in my project. But it seems an ugly solution to me to get the values out of this file?

Sandun
  • 395
  • 2
  • 10
  • 25
lvthillo
  • 28,263
  • 13
  • 94
  • 127

1 Answers1

2

I had similar issue. I found the solution here https://blog.corpinfo.com/how-to-call-and-export-variables-in-elastic-beanstalk

For unix you can simply write

commands:
  010-01-test:
    command: echo $(/opt/elasticbeanstalk/bin/get-config environment -k DB.Username)

or even $(get-config environment -k DB.Username):

I don't know how to expose this inline in windows, but there are should be a way.

Alternative you can try more verbose solution

commands:
  010-01-test:
    command: echo %DBUsername%
    env:
      DBUsername: 
        "Fn::GetOptionSetting":
          Namespace: "aws:elasticbeanstalk:application:environment"
          OptionName: DB.Username
iMysak
  • 2,170
  • 1
  • 22
  • 35
  • Does the above need to be run directly on the EC2 instance of the beanstalk? Can I run it in a way similar to "describe-environments" ? – mdabdullah Nov 27 '20 at 19:58
  • 1
    You may try describe-configuration-settings if CLI is what you need – iMysak Nov 28 '20 at 20:21
  • That actually worked! For anyone else looking, you may need to `yum install jq` if you are trying to fetch a particular value. Example: `aws elasticbeanstalk describe-configuration-settings --application-name appname --environment-name envname | jq '.ConfigurationSettings[].OptionSettings'| jq '.[] | select(.OptionName=="IMPORTANT_CONFIG_VALUE")'|jq '.Value'` – mdabdullah Nov 30 '20 at 15:18