

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

# 使用同步配置
<a name="syncconfigurations"></a>

同步配置在指定的存储库和连接之间创建关联。使用同步配置可同步 Git 存储库中的内容以更新指定 AWS 资源。

有关连接的更多信息，请参阅 [AWS CodeConnections API 参考](https://docs.aws.amazon.com/codestar-connections/latest/APIReference/Welcome.html)。

**Topics**
+ [创建同步配置](syncconfigurations-create.md)
+ [更新同步配置](syncconfigurations-update.md)
+ [列出同步配置](syncconfigurations-list.md)
+ [删除同步配置](syncconfigurations-delete.md)
+ [查看同步配置详细信息](syncconfigurations-view-details.md)

# 创建同步配置
<a name="syncconfigurations-create"></a>

您可以使用 AWS Command Line Interface (AWS CLI) 中的**create-repository-link**命令在连接和要同步到的外部存储库之间创建链接。

在创建同步配置之前，您必须已经在连接和第三方存储库之间创建了存储库链接。

**创建同步配置**

1. 打开终端（Linux、macOS 或 Unix）或命令提示符（Windows）。 AWS CLI 使用运行**create-repository-link**命令。指定关联连接的 ARN、所有者 ID 和存储库名称。以下命令将创建一个同步配置，其同步类型适用于 CloudFormation中的资源。它还指定了存储库分支和存储库中的配置文件。在此示例中，资源是一个名为 **`mystack`** 的堆栈。

   ```
   aws codeconnections create-sync-configuration --branch main --config-file filename --repository-link-id be8f2017-b016-4a77-87b4-608054f70e77 --resource-name mystack --role-arn arn:aws:iam::account_id:role/myrole --sync-type CFN_STACK_SYNC
   ```

1. 此命令将返回以下输出。

   ```
   {
       "SyncConfiguration": {
           "Branch": "main",
           "ConfigFile": "filename",
           "OwnerId": "account_id",
           "ProviderType": "GitHub",
           "RepositoryLinkId": "be8f2017-b016-4a77-87b4-608054f70e77",
           "RepositoryName": "MyRepo",
           "ResourceName": "mystack",
           "RoleArn": "arn:aws:iam::account_id:role/myrole",
           "SyncType": "CFN_STACK_SYNC"
       }
   ```

# 更新同步配置
<a name="syncconfigurations-update"></a>

您可以在 AWS Command Line Interface (AWS CLI) 中使用 **update-sync-configuration** 命令更新指定同步配置。

您可以更新同步配置的以下信息：
+ `--branch`
+ `--config-file`
+ `--repository-link-id`
+ `--resource-name`
+ `--role-arn`

**更新同步配置**

1. 打开终端（Linux、macOS 或 Unix）或命令提示符（Windows）。使用运行**update-sync-configuration**命令，指定要更新的值以及资源名称和同步类型。 AWS CLI 例如，以下命令使用 `--branch` 参数更新与同步配置关联的分支名称。

   ```
   aws codeconnections update-sync-configuration --sync-type CFN_STACK_SYNC --resource-name mystack --branch feature-branch
   ```

1. 此命令将返回以下输出。

   ```
   {
       "SyncConfiguration": {
           "Branch": "feature-branch",
           "ConfigFile": "filename.yaml",
           "OwnerId": "owner_id",
           "ProviderType": "GitHub",
           "RepositoryLinkId": "6053346f-8a33-4edb-9397-10394b695173",
           "RepositoryName": "MyRepo",
           "ResourceName": "mystack",
           "RoleArn": "arn:aws:iam::account_id:role/myrole",
           "SyncType": "CFN_STACK_SYNC"
       }
   ```

# 列出同步配置
<a name="syncconfigurations-list"></a>

您可以在 AWS Command Line Interface (AWS CLI) 中使用 **list-sync-configurations** 命令列出您账户中的存储库链接。

**列出存储库链接**

1. 打开终端（Linux、macOS 或 Unix）或命令提示符（Windows）。使用运行**list-sync-configurations**命令，指定同步类型和存储库链接 ID。 AWS CLI 

   ```
   aws codeconnections list-sync-configurations --repository-link-id 6053346f-8a33-4edb-9397-10394b695173  --sync-type CFN_STACK_SYNC 
   ```

1. 此命令将返回以下输出。

   ```
   {
       "SyncConfigurations": [
           {
               "Branch": "main",
               "ConfigFile": "filename.yaml",
               "OwnerId": "owner_id",
               "ProviderType": "GitHub",
               "RepositoryLinkId": "6053346f-8a33-4edb-9397-10394b695173",
               "RepositoryName": "MyRepo",
               "ResourceName": "mystack",
               "RoleArn": "arn:aws:iam::account_id:role/myrole",
               "SyncType": "CFN_STACK_SYNC"
           }
       ]
   }
   ```

# 删除同步配置
<a name="syncconfigurations-delete"></a>

您可以在 AWS Command Line Interface (AWS CLI) 中使用 **delete-sync-configuration** 命令删除同步配置。

**重要**  
运行该命令后，将删除同步配置。不显示任何确认对话框。您可以创建新的同步配置，但无法重复使用 Amazon 资源名称 (ARN)。

**删除同步配置**
+ 打开终端（Linux、macOS 或 Unix）或命令提示符（Windows）。使用运行**delete-sync-configuration**命令，为 AWS CLI 要删除的同步配置指定同步类型和资源名称。

  ```
  aws codeconnections delete-sync-configuration --sync-type CFN_STACK_SYNC --resource-name mystack
  ```

  该命令不返回任何内容。

# 查看同步配置详细信息
<a name="syncconfigurations-view-details"></a>

您可以使用 AWS Command Line Interface (AWS CLI) 中的**get-sync-configuration**命令来查看同步配置的详细信息。

**查看同步配置详细信息**

1. 打开终端（Linux、macOS 或 Unix）或命令提示符（Windows）。 AWS CLI 使用运行**get-sync-configuration**命令，指定存储库链接 ID。

   ```
   aws codeconnections get-sync-configuration --sync-type CFN_STACK_SYNC --resource-name mystack
   ```

1. 此命令将返回以下输出。

   ```
   {
       "SyncConfiguration": {
           "Branch": "main",
           "ConfigFile": "filename",
           "OwnerId": "owner_id",
           "ProviderType": "GitHub",
           "RepositoryLinkId": "be8f2017-b016-4a77-87b4-608054f70e77",
           "RepositoryName": "MyRepo",
           "ResourceName": "mystack",
           "RoleArn": "arn:aws:iam::account_id:role/myrole",
           "SyncType": "CFN_STACK_SYNC"
       }
   }
   ```