Why Integrating Spring Cloud application with the AWS Parameter Store return no property from param store?

只愿长相守 提交于 2019-12-12 09:01:36

问题


Intent : I am working on a POC which intends to use AWS Parameter store as a property store.This would store the confidential application properties in AWS SSM's Parameter store.I am using Java 8 with spring boot/cloud version 2.

Resource : I followed this ref guide from spring docs and

also a comprehensive article Integrating the AWS Parameter Store with Spring Cloud .Hence was trying to utilize

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

and hence added required dependency in the build file.

Expected output :

Actual output :

Here is snapshot from AWS console I am trying to access below shown parameters from AWS parameter store

Below are my spring property files:

application.yml

bootstrap.yml

I am using maven with below dependencies in POM.xml

    <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>

Am I missing something here?? Please let me know if someone has already faced and resolved this issue.

I am able to put and get parameter from command line,its just not able to get this java lib working.

GitHub repo of the sample I am trying -

GitHub repo link


回答1:


I checked your app, it didn't work as expected for me as I had ~.aws/config file which leads to misconfiguration of AWS credentials(cause by DefaultAWSCredentialsProviderChain, read more here ), so I removed it, and I tried again but it fails saying that spring can't find aws region in the env, so apparently those specified in application.yml won't be used until spring loads properties from AWS parameter store.

How I made it work

I added:

        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

before SpringApplication.run(DemoApplication.class, args); and then it worked.

when changing the aws.region to another one where there are no params value defined I got the exact same result as yours (empty values).

make sure there isn't any aws config on your machine or EC2 instance that will override those provided in your app.



来源:https://stackoverflow.com/questions/54050702/why-integrating-spring-cloud-application-with-the-aws-parameter-store-return-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!