为什么将Spring Cloud应用程序与AWS Parameter Store集成在一起不会从param store返回任何属性?

时间:2019-01-05 09:29:24

标签: java amazon-web-services spring-boot spring-cloud spring-cloud-config

意图:我正在一个POC上,该POC打算将AWS Parameter存储用作属性存储。这会将机密应用程序属性存储在AWS SSM的Parameter存储中。我正在将Java 8与spring一起使用引导/云版本2。

资源:我遵循了Spring文档中的this ref guide

也是一篇全面的文章Integrating the AWS Parameter Store with Spring Cloud。因此,他试图利用

  

spring-cloud-starter-aws-parameter-store-config.jar

,因此在构建文件中添加了必需的依赖项。

预期输出:

enter image description here

实际输出

enter image description here

这是 AWS控制台的快照,我正在尝试从AWS参数存储中访问以下所示的参数

enter image description here

下面是我的spring属性文件:

application.yml

enter image description here

bootstrap.yml

enter image description here

我正在使用 POM.xml

中具有以下依赖项的maven
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-parameter-store-config</artifactId>
        </dependency>
    </dependencies>

我在这里错过了什么吗?请让我知道是否有人已经解决了这个问题。

我能够从命令行放置和获取参数,只是无法使该Java库正常工作。

我正在尝试的示例的GitHub回购-

GitHub repo link

1 个答案:

答案 0 :(得分:0)

我检查了您的应用程序,因为我有〜.aws / config文件,该应用程序无法正常运行,这导致AWS凭证配置错误(由DefaultAWSCredentialsProviderChain引起,更多信息here) ,因此我将其删除,然后再次尝试,但未能说出spring无法在环境中找到aws区域,因此,显然只有在spring从AWS参数存储加载属性后,才会使用application.yml中指定的区域。

我是如何工作的

我添加了:

        System.setProperty("aws.accessKeyId","My_Key");
        System.setProperty("aws.secretKey","Secret");
        System.setProperty("aws.region","us-east-1");//same region where all your params exist

SpringApplication.run(DemoApplication.class, args);之前,然后有效。

当将aws.region更改为未定义参数值的另一个值时,我得到的结果与您的结果完全相同(空值)。

确保您的计算机或EC2实例上没有任何AWS配置会覆盖您应用中提供的配置。