

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 配置 Amazon AppConfig 代理以将配置副本写入磁盘


您可以将 Amazon AppConfig Agent 配置为以纯文本形式自动将配置副本存储到磁盘。此功能使客户能够将从磁盘读取配置数据的应用程序与 Amazon AppConfig集成。

此功能不是为用作配置备份功能而设计的。 Amazon AppConfig 代理无法读取复制到磁盘的配置文件。如果要将配置备份到磁盘，请参阅在 Amazon EC2 中[使用 Amazon AppConfig 代理或在 Amazon ECS `BACKUP_DIRECTORY` 和 Amazon](https://docs.amazonaws.cn/appconfig/latest/userguide/appconfig-integration-ec2.html#appconfig-integration-ec2-configuring) [EKS 中使用 Amazon AppConfig 代理的和`PRELOAD_BACKUP`环境变量](https://docs.amazonaws.cn/appconfig/latest/userguide/appconfig-integration-containers-agent.html#appconfig-integration-containers-agent-configuring)。

**警告**  
请注意有关此功能的以下重要信息：  
保存到磁盘的配置以*纯文本* 形式存储，便于用户阅读。请勿为包含敏感数据的配置启用此功能。
此功能将内容写入本地磁盘。对文件系统权限使用最低权限原则。有关更多信息，请参阅 [实施最低权限访问](appconfig-security.md#appconfig-security-least-privilege-access)。

**启用将配置副本写入磁盘**

1. 编辑清单。

1. 选择 Amazon AppConfig 要写入磁盘的配置并添加`writeTo`元素。示例如下：

   ```
   {
       "application_name:environment_name:configuration_name": {
           "writeTo": {
               "path": "path_to_configuration_file"
           }
       }
   }
   ```

   示例如下：

   ```
   {
       "MyTestApp:MyTestEnvironment:MyNewConfiguration": {
           "writeTo": {
               "path": "/tmp/aws-appconfig/mobile-app/beta/enable-mobile-payments"
           }
       }
   }
   ```

1. 保存更改。每次部署新的配置数据时，都会更新 configuration.json 文件。

**验证将配置副本写入磁盘是否正常工作**  
您可以通过查看 Amazon AppConfig 代理日志来验证配置副本是否正在写入磁盘。带有 “INFO 将配置写入 '*application*:*environment*: *configuration* '到*file\$1path*” 的`INFO`日志条目表示 Amazon AppConfig 代理将配置副本写入磁盘。

示例如下：

```
[appconfig agent] 2023/11/13 11:33:27 INFO AppConfig Agent 2.0.x
[appconfig agent] 2023/11/13 11:33:28 INFO serving on localhost:2772
[appconfig agent] 2023/11/13 11:33:28 INFO retrieved initial data for 'MobileApp:Beta:EnableMobilePayments' in XX.Xms
[appconfig agent] 2023/11/13 17:05:49 INFO wrote configuration 'MobileApp:Beta:EnableMobilePayments' to /tmp/configs/your-app/your-env/your-config.json
```