Reputation: 15066
I have set environment properties in AWS Elastic beanstalk. I have a nodejs application which is hosted on a linux.
I can read the environment properties by using container_commands in a config in ebextensions.
But is there another way to read those values? Can you export a json or something of all the values without reading them as environment variables in ebextensions?
Upvotes: 4
Views: 3142
Reputation: 1
eb config get --output json > environment-config.json
const environmentConfig = require('./environment-config.json');
const environmentProperties = environmentConfig.ConfigurationSettings[0].OptionSettings.filter(setting => setting.Namespace === 'aws:elasticbeanstalk:application:environment');
Upvotes: 0
Reputation: 21
Just in case anyone else bumps into this after all this time, I actually filed a support request with AWS and have a reasonable answer, which I'm including below. The bottom line for me was that it turns out that there are two completely different AWS CLIs for EB(!). There's this one:
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html#available-services
which is the one I always go to even to hunt for stuff in their SDKs, but which is completely unable to return the environment properties, and this one, which is completely separate from the normal AWS CLI distro:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html
I had no idea until this existed until just now, and it can do the desired stuff.
Because I always use the CLI as a guide to finding SDK functionality (the docs generally being so bad), and because I looked at the former CLI, I didn't discover that (at least for recent releases) the SDKs in different languages can also do this stuff:
https://docs.aws.amazon.com/elasticbeanstalk/latest/api/API_Operations.html
I've verified that at least the PHP SDK can read an environment's properties using Aws\ElasticBeanstalk\ElasticBeanstalkClient::ConfigurationSettings which returns more than you want, but you can filter the results testing for Namespace == "aws:elasticbeanstalk:application:environment"
All available Elastic Beanstalk (EB) API actions can be found at [1].
The DescribeConfigurationSettings [2] action will return a description of the settings for the specified configuration set, that is, either a configuration template or the configuration set associated with a running environment. On the "See Also" section of the API action pages, is the related SDK and CLI documentation for that action.
The eb config
[3] "EB CLI" [4] command can also be used to describe the environment configuration as well as update the environment.
The "UpdateEnvironment" [5] API action can be used to update environment properties.
CloudTrail events history [6] can be used to see which actions are performed when, for example, an environment is updated. CloudTrail events require a few minutes to display the event after the action is performed.
Saved configurations [7] can be used to apply a particular set of configurations to other environments, to ensure consistency.
To Summarize:
eb config
[3].eb config
[3].I hope you find the above informative and don't hesitate to reach out with further questions!
Have a great day ahead.
References: [1] - AWS Elastic Beanstalk Actions https://docs.aws.amazon.com/elasticbeanstalk/latest/api/API_Operations.html
[2] - DescribeConfigurationSettings https://docs.aws.amazon.com/elasticbeanstalk/latest/api/API_DescribeConfigurationSettings.html
[3] - eb config https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-config.html
[4] - Using the Elastic Beanstalk command line interface (EB CLI) https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html
[5] - UpdateEnvironment https://docs.aws.amazon.com/elasticbeanstalk/latest/api/API_UpdateEnvironment.html#API_UpdateEnvironment_SeeAlso
[6] - Viewing recent management events with the console https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events-console.html
[7] - Using Elastic Beanstalk saved configurations https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-savedconfig.html
We value your feedback. Please share your experience by rating this and other correspondences in the AWS Support Center. You can rate a correspondence by selecting the stars in the top right corner of the correspondence.
Upvotes: 0
Reputation: 1746
commands:
setvars:
command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' > /etc/profile.d/sh.local
packages:
yum:
jq: []
https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-shell/
Upvotes: 0
Reputation: 679
You can get environment variables with get-command
on a Beanstalk EC2 instance:
sudo /opt/elasticbeanstalk/bin/get-config environment --output json
Upvotes: 9