代码之家  ›  专栏  ›  技术社区  ›  Mahesh_Loya

为什么将SpringCloud应用程序与AWS参数存储集成时不会从param存储返回任何属性?

  •  0
  • Mahesh_Loya  · 技术社区  · 7 年前

    意图 :我正在开发一个POC,该POC打算将AWS参数存储用作属性存储。这将在AWS SSM的参数存储中存储机密应用程序属性。我正在使用Java 8和spring boot/cloud版本2。

    this ref guide 来自spring文档

    也是一篇综合性文章 Integrating the AWS Parameter Store with Spring Cloud

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

    预期产出:

    enter image description here

    :

    enter image description here

    enter image description here

    下面是我的spring属性文件:

    application.yml

    enter image description here

    bootstrap.yml

    enter image description here

    我正在使用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 repo link

    1 回复  |  直到 7 年前
        1
  •  4
  •   stacker    7 年前

    我检查了你的应用程序,它没有像我预期的那样工作,因为我有~.aws/config文件,这导致了aws凭据的错误配置(原因是 DefaultAWSCredentialsProviderChain ,阅读更多 here

    我是怎么做到的

            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