AWS S3 后端
Spring Cloud Config Server 支持 AWS S3 作为配置属性的后端。您可以通过添加对 适用于 Amazon S3 的 AWS Java SDK 的依赖项来启用此功能。
pom.xml
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies>
以下配置使用 AWS S3 客户端访问配置文件。我们可以使用 spring.cloud.config.server.awss3.* 属性来选择存储配置的存储桶。
spring:
profiles:
active: awss3
cloud:
config:
server:
awss3:
region: us-east-1
bucket: bucket1
还可以指定 AWS URL 来 覆盖 S3 服务的标准端点,使用 spring.cloud.config.server.awss3.endpoint。这允许支持 S3 的 Beta 区域以及其他与 S3 兼容的存储 API。
凭证是使用 默认凭证提供程序链 找到的。无需进一步配置即可支持版本化和加密的存储桶。
默认情况下,配置文件以 {application}-{profile}.properties、{application}-{profile}.yml 或 {application}-{profile}.json 的形式存储在您的存储桶中。可以提供一个可选标签来指定文件的目录路径。
未指定配置文件时,将使用 default。 |
目录布局
Spring Cloud Config Server 还支持类似于 Git 后端中 search-paths: '{application}' 的每应用程序目录布局。
要启用它,请将 useDirectoryLayout 属性设置为 true,如以下示例所示
spring:
cloud:
config:
server:
awss3:
region: us-east-1
bucket: bucket1
useDirectoryLayout: true
前面的列表匹配存储在您的存储桶中 /{application} 目录中的对象,例如:/{application}/application\{-profile}.yml。那么存储桶的结构应该如下所示
├── foo
│ ├── application-test.yml
│ └── application.yml
├── bar
│ ├── application-test.yml
│ └── application.yml