我正在使用适用于AWS Elastic Beanstalk的Java SDK,并且在获取有关我的EB环境的信息方面取得了很大成功。我完全坚持的一个地方是获取Environment Properties的列表。我希望找到像EnvironmentDescription这样的列表。但他们不在那里。我知道这可以通过EB CLI实现,它通常与SDK的比例接近1:1。
有谁知道我需要做些什么来获取环境的这些环境属性列表?
注意:我使用的是com.amazonaws.aws-java-sdk-elasticbeanstalk的1.11.279版,但如果在以后的版本中获得这些属性,则可以更改。
编辑:他们被发现了!它需要意识到环境。变量通过ElasticBeanstalk中的配置面板设置。下面是关于如何获取列表的Java代码(为清楚起见而编写)。// Included for verbosity
AWSElasticBeanstalk eb = AWSElasticBeanstalkClientBuilder.standard().build());
// Build the configuration request, send it via eb, and obtain the result
DescribeConfigurationSettingsRequest request = new DescribeConfigurationSettingsRequest();
request.setEnvironmentName(environmentName);
request.setApplicationName(applicationName);
DescribeConfigurationSettingsResult result = eb.describeConfigurationSettings(request);
// List of my own class which simply has a "key" and a "value" field
List<EnvironmentVariable> environmentVariables = new ArrayList<>();
for (ConfigurationSettingsDescription description: result.getConfigurationSettings()) {
for (ConfigurationOptionSetting setting : description.getOptionSettings() {
// We get back a list of all configuration items, we only want the ones namespaced as environment variables
if ("aws:elasticbeanstalk:application:environment".equals(setting.getNamespace()) {
environmentVariables.add(new EnvironmentVariable(setting.getOptionName(), setting.getValue());
}
}
}