AWS S3 后端

Spring Cloud 配置服务器支持 AWS S3 作为配置属性的后端。 您可以通过在AWS Java SDK For Amazon S3中添加依赖来启用此功能。spring-doc.cadn.net.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>software.amazon.awssdk</groupId>
		<artifactId>s3</artifactId>
	</dependency>
</dependencies>

以下配置使用 AWS S3 客户端访问配置文件。我们可以使用Spring.cloud.config.server.awss3.*属性来选择存储配置的桶。spring-doc.cadn.net.cn

spring:
  profiles:
    active: awss3
  cloud:
    config:
      server:
        awss3:
          region: us-east-1
          bucket: bucket1

你也可以指定一个 AWS URL,覆盖你 S3 服务的标准端点Spring.cloud.config.server.awss3.endpoint.这使得支持 S3 的测试版区域以及其他兼容 S3 的存储 API。spring-doc.cadn.net.cn

凭证通过默认凭证提供者链(Default Credential Provider Chain)找到。支持版本化和加密桶,无需额外配置。spring-doc.cadn.net.cn

默认情况下,配置文件存储在你的桶中,格式如下{application}-{profile}.properties,{application}-{profile}.yml{application}-{profile}.json.可提供可选标签以指定文件的目录路径。spring-doc.cadn.net.cn

当没有指定配置文件时默认值将被使用。

目录布局

Spring Cloud 配置服务器还支持类似的每个应用目录布局搜索路径:'{application}'在Git后端。spring-doc.cadn.net.cn

为了启用它,设置useDirectoryLayout属性到true如下例所示:spring-doc.cadn.net.cn

spring:
  cloud:
    config:
      server:
        awss3:
          region: us-east-1
          bucket: bucket1
          useDirectoryLayout: true

前面的列表匹配了存储在/{application}目录像:/{application}/application\{-profile}.yml.那么桶的结构应该是这样的:spring-doc.cadn.net.cn

├── foo
│   ├── application-test.yml
│   └── application.yml
├── bar
│   ├── application-test.yml
│   └── application.yml