Java 如何从AWS参数存储中获取spring数据源属性值?

Java 如何从AWS参数存储中获取spring数据源属性值?,java,spring-boot,aws-parameter-store,Java,Spring Boot,Aws Parameter Store,在我的spring引导应用程序中,我在application.properties文件中维护了spring.datasource.url。我需要保护URL/用户和密码,并且这些值在AWS参数存储中可用。我引用了这一点,只是添加了对(SpringCloudStarter aws参数存储配置)starter模块的依赖项来激活支持。我实际上不知道如何维护配置参数,以及如何将参数存储值检索到我的项目中 如果不使用以下(application.properties)属性中的硬编码值,如何实现这一点 spr

在我的spring引导应用程序中,我在application.properties文件中维护了spring.datasource.url。我需要保护URL/用户和密码,并且这些值在AWS参数存储中可用。我引用了这一点,只是添加了对(SpringCloudStarter aws参数存储配置)starter模块的依赖项来激活支持。我实际上不知道如何维护配置参数,以及如何将参数存储值检索到我的项目中

如果不使用以下(application.properties)属性中的硬编码值,如何实现这一点

spring.datasource.url= url
spring.datasource.username = root
spring.datasource.password = xxxxxx

要在Spring Boot应用程序中将AWS System Manager参数存储用作
属性源
,请执行以下步骤

将以下依赖项添加到
build.gradle

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3'
    }
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config'
}
将指定应用程序名称的属性添加到
src/main/resources/bootstrap.properties
中:

spring.application.name=my-app
默认情况下,Spring Cloud AWS依赖于和

如果应用程序在EC2/Fargate实例上运行而不是,请通过设置以下环境变量来配置AWS凭据和区域:

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=us-west-1
或者确保您拥有有效的AWS配置文件
~/.AWS/credentials
~/.AWS/config

在AWS系统管理器参数存储中定义以下属性:

/config/my-app/spring.datasource.url
/config/my-app/spring.datasource.username
/config/my-app/spring.datasource.password

要在Spring Boot应用程序中将AWS System Manager参数存储用作
属性源
,请执行以下步骤

将以下依赖项添加到
build.gradle

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3'
    }
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-aws-parameter-store-config'
}
将指定应用程序名称的属性添加到
src/main/resources/bootstrap.properties
中:

spring.application.name=my-app
默认情况下,Spring Cloud AWS依赖于和

如果应用程序在EC2/Fargate实例上运行而不是,请通过设置以下环境变量来配置AWS凭据和区域:

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=us-west-1
或者确保您拥有有效的AWS配置文件
~/.AWS/credentials
~/.AWS/config

在AWS系统管理器参数存储中定义以下属性:

/config/my-app/spring.datasource.url
/config/my-app/spring.datasource.username
/config/my-app/spring.datasource.password

是否可以从AWS参数存储中处理AWS凭据?因为我们处于暂存环境中,所以不使用EC2 machineAWS凭据的配置,必须在环境变量、系统属性或文件(~/.aws/credentials)中指定区域。查看应用程序是否在aws云(EC2/Fargate)中运行,然后spring云足够智能,可以获得aws凭据。我们不需要配置任何环境变量或~/.aws/*。确保您有spring cloud aws自动配置依赖项addedSpring cloud没有配置aws凭据,它依赖于这一点来最好地找到aws凭据提供程序。请参阅Javadoc。是否可以从AWS参数存储中处理AWS凭据?因为我们处于暂存环境中,所以不使用EC2 machineAWS凭据的配置,必须在环境变量、系统属性或文件(~/.aws/credentials)中指定区域。查看应用程序是否在aws云(EC2/Fargate)中运行,然后spring云足够智能,可以获得aws凭据。我们不需要配置任何环境变量或~/.aws/*。确保您有spring cloud aws自动配置依赖项addedSpring cloud没有配置aws凭据,它依赖于这一点来最好地找到aws凭据提供程序。请参阅Javadoc。