

# Working with sync configurations
<a name="syncconfigurations"></a>

A sync configuration creates an association between a specified repository and connection. Use the sync configuration to sync content from a Git repository to update a specified AWS resource. 

For more information about connections, see the [AWS CodeConnections API reference](https://docs.aws.amazon.com/codestar-connections/latest/APIReference/Welcome.html).

**Topics**
+ [Create a sync configuration](syncconfigurations-create.md)
+ [Update a sync configuration](syncconfigurations-update.md)
+ [List sync configurations](syncconfigurations-list.md)
+ [Delete a sync configuration](syncconfigurations-delete.md)
+ [View sync configuration details](syncconfigurations-view-details.md)

# Create a sync configuration
<a name="syncconfigurations-create"></a>

You can use the **create-repository-link** command in the AWS Command Line Interface (AWS CLI) to create a link between your connection and the external repository to sync to.

Before you can create a sync configuration, you must have already created a repository link between your connection and your third-party repository.

**To create a sync configuration**

1. Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **create-repository-link** command. Specify the ARN of the associated connection, the owner ID, and the repository name. The following command creates a sync configuration with a sync type for a resource in CloudFormation. It also specifies the repository branch and configuration file in the repository. In this example, the resource is a stack named **`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. This command returns the following output.

   ```
   {
       "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"
       }
   ```

# Update a sync configuration
<a name="syncconfigurations-update"></a>

You can use the **update-sync-configuration** command in the AWS Command Line Interface (AWS CLI) to update a specified sync configuration.

You can update the following information for your sync configuration:
+ `--branch`
+ `--config-file`
+ `--repository-link-id`
+ `--resource-name`
+ `--role-arn`

**To update a sync configuration**

1. Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **update-sync-configuration** command, specifying the value you want to update, along with the resource name and sync type. For example, the following command updates the branch name associated to the sync configuration with the `--branch` parameter.

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

1. This command returns the following output.

   ```
   {
       "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"
       }
   ```

# List sync configurations
<a name="syncconfigurations-list"></a>

You can use the **list-sync-configurations** command in the AWS Command Line Interface (AWS CLI) to list repository links for your account.

**To list repository links**

1. Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **list-sync-configurations** command, specifying the sync type and repository link ID.

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

1. This command returns the following output.

   ```
   {
       "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"
           }
       ]
   }
   ```

# Delete a sync configuration
<a name="syncconfigurations-delete"></a>

You can use the **delete-sync-configuration** command in the AWS Command Line Interface (AWS CLI) to delete a sync configuration.

**Important**  
After you run the command, the sync configuration is deleted. No confirmation dialog box is displayed. You can create a new sync configuration, but the Amazon Resource Name (ARN) is not reused.

**To delete a sync configuration**
+ Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **delete-sync-configuration** command, specifying the sync type and resource name for the sync configuration that you want to delete.

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

  This command returns nothing.

# View sync configuration details
<a name="syncconfigurations-view-details"></a>

You can use the **get-sync-configuration** command in the AWS Command Line Interface (AWS CLI) to view details for a sync configuration.

**To view details for a sync configuration**

1. Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **get-sync-configuration** command, specifying the repository link ID.

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

1. This command returns the following output.

   ```
   {
       "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"
       }
   }
   ```