amazon-web-servicesamazon-elastic-beanstalk

Elastic Beanstalk app.config option_settings with dynamic environment variables not working


I am using an app.config as seen here:

{
    "option_settings": [
        {
            "namespace": "aws:elasticbeanstalk:application:environment",
            "option_name": "AWS_ENVIRONMENT_NAME",
            "value": "`{ \"Ref\" : \"AWSEBEnvironmentName\" }`"
        },
        {
            "namespace": "aws:elasticbeanstalk:application:environment",
            "option_name": "AWS_ENVIRONMENT_ID",
            "value": "`{ \"Ref\" : \"AWSEBEnvironmentId\" }`"
        }
    ]
}

But when I deploy the version with my config to an environment, the variables are not substituted in:

AWS environment variables from UI


Solution

  • That's how it shows in the console. But in the instance it should be correctly resolved.

    You can ssh into the instance and verify:

    sudo cat /opt/elasticbeanstalk/deployment/env
    

    If it in fact it does not work, you can use the following yaml syntax which works:

    option_settings:
        - namespace: aws:elasticbeanstalk:application:environment
          option_name: AWS_ENVIRONMENT_NAME
          value: '`{ "Ref" : "AWSEBEnvironmentName" }`'
        - namespace: aws:elasticbeanstalk:application:environment
          option_name: AWS_ENVIRONMENT_ID
          value: '`{ "Ref" : "AWSEBEnvironmentId" }`'  
    

    Note, it will still show as { "Ref" : "AWSEBEnvironmentId" } in EB config window, but inside the instance it will be correctly resolved.