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
© . This site is unofficial and not affiliated with VMware.