

# Working with sync configurations for linked repositories
<a name="configurations"></a>

In AWS CodeConnections, you use a connection to associate AWS resources to a third-party repository, such as GitHub, Bitbucket Cloud, GitHub Enterprise Server, and GitLab. Using the `CFN_STACK_SYNC` sync type, you can create a sync configuration, which allows AWS to sync content from a Git repository to update a specified AWS resource. CloudFormation integrates with connections so that you can use Git sync to manage your template and parameter files in a linked repository that you sync with.

After creating a connection, you can use the connections CLI or the CloudFormation console to create your repository link and sync configuration. 
+ Repository link: A repository link creates an association between your connection and an external Git repository. The repository link allows Git sync to monitor and sync changes to files in a specified Git repository.
+ Sync configuration: Use the sync configuration to sync content from a Git repository to update a specified AWS resource. 

For more information, see the [https://docs.aws.amazon.com/codeconnections/latest/APIReference/Welcome.html](https://docs.aws.amazon.com/codeconnections/latest/APIReference/Welcome.html). 

For a tutorial that walks you through creating a sync configuration for an CloudFormation stack using the CloudFormation console, see [Working with CloudFormation Git sync](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/git-sync.html) in the *CloudFormation User Guide*.

**Topics**
+ [Working with repository links](repositorylinks.md)
+ [Working with sync configurations](syncconfigurations.md)

# Working with repository links
<a name="repositorylinks"></a>

A repository link creates an association between your connection and an external Git repository. The repository link allows Git sync to monitor and sync changes to files in a specified Git repository to an CloudFormation stack.

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

**Topics**
+ [Create a repository link](repositorylinks-create.md)
+ [Update a repository link](repositorylinks-update.md)
+ [List repository links](repositorylinks-list.md)
+ [Delete a repository link](repositorylinks-delete.md)
+ [View repository link details](repositorylinks-view-details.md)

# Create a repository link
<a name="repositorylinks-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 repository link, you must have already created your external repository with your third-party provider, such as GitHub.

**To create a repository link**

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.

   ```
   aws codeconnections create-repository-link --connection-arn  arn:aws:codeconnections:us-east-1:account_id:connection/001f5be2-a661-46a4-b96b-4d277cac8b6e --owner-id account_id --repository-name MyRepo 
   ```

1. This command returns the following output.

   ```
   {
       "RepositoryLinkInfo": {
           "ConnectionArn": "arn:aws:codeconnections:us-east-1:account_id:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
           "OwnerId": "account_id",
           "ProviderType": "GitHub",
           "RepositoryLinkArn": "arn:aws:codeconnections:us-east-1:account_id:repository-link/be8f2017-b016-4a77-87b4-608054f70e77",
           "RepositoryLinkId": "be8f2017-b016-4a77-87b4-608054f70e77",
           "RepositoryName": "MyRepo",
           "Tags": []
       }
   }
   ```

# Update a repository link
<a name="repositorylinks-update"></a>

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

You can update the following information for your repository link:
+ `--connection-arn`
+ `--owner-id`
+ `--repository-name`

You might update a repository link when you want to change the connection that is associated with your repository. To use a different connection, you need to specify the connection ARN. For the steps to view your connection ARN, see [View connection details](connections-view-details.md).

**To update a repository link**

1. Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **update-repository-link** command, specifying the value to update for the repository link. For example, the following command updates the connection associated to the repository link ID. It specifies the new connection ARN with the `--connection` parameter.

   ```
   aws codestar-connections update-repository-link --repository-link-id 6053346f-8a33-4edb-9397-10394b695173 --connection-arn arn:aws:codestar-connections:us-east-1:account_id:connection/aEXAMPLE-f055-4843-adef-4ceaefcb2167 
   ```

1. This command returns the following output.

   ```
   {
       "RepositoryLinkInfo": {
           "ConnectionArn": "arn:aws:codestar-connections:us-east-1:account_id:connection/aEXAMPLE-f055-4843-adef-4ceaefcb2167",
           "OwnerId": "owner_id",
           "ProviderType": "GitHub",
           "RepositoryLinkArn": "arn:aws:codestar-connections:us-east-1:account_id:repository-link/6053346f-8a33-4edb-9397-10394b695173",
           "RepositoryLinkId": "6053346f-8a33-4edb-9397-10394b695173",
           "RepositoryName": "MyRepo",
           "Tags": []
       }
   }
   ```

# List repository links
<a name="repositorylinks-list"></a>

You can use the **list-repository-links** 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-repository-links ** command.

   ```
   aws codeconnections list-repository-links
   ```

1. This command returns the following output.

   ```
   {
       "RepositoryLinks": [
           {
               "ConnectionArn": "arn:aws:codestar-connections:us-east-1:account_id:connection/001f5be2-a661-46a4-b96b-4d277cac8b6e",
               "OwnerId": "owner_id",
               "ProviderType": "GitHub",
               "RepositoryLinkArn": "arn:aws:codestar-connections:us-east-1:account_id:repository-link/6053346f-8a33-4edb-9397-10394b695173",
               "RepositoryLinkId": "6053346f-8a33-4edb-9397-10394b695173",
               "RepositoryName": "MyRepo",
               "Tags": []
           }
       ]
   }
   ```

# Delete a repository link
<a name="repositorylinks-delete"></a>

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

Before you can delete a repository link, you must delete all sync configurations associated with the repository link.

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

**To delete a repository link**
+ Open a terminal (Linux, macOS, or Unix) or command prompt (Windows). Use the AWS CLI to run the **delete-repository-link** command, specifying the ID of the repository link to delete.

  ```
  aws codeconnections delete-repository-link --repository-link-id 6053346f-8a33-4edb-9397-10394b695173
  ```

  This command returns nothing.

# View repository link details
<a name="repositorylinks-view-details"></a>

You can use the **get-repository-link** command in the AWS Command Line Interface (AWS CLI) to view details about a repository link.

**To view repository link details**

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

   ```
   aws codestar-connections get-repository-link --repository-link-id 6053346f-8a33-4edb-9397-10394b695173
   ```

1. This command returns the following output.

   ```
   {
       "RepositoryLinkInfo": {
           "ConnectionArn": "arn:aws:codestar-connections:us-east-1:account_id:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f",
           "OwnerId": "owner_id",
           "ProviderType": "GitHub",
           "RepositoryLinkArn": "arn:aws:codestar-connections:us-east-1:account_id:repository-link/be8f2017-b016-4a77-87b4-608054f70e77",
           "RepositoryLinkId": "6053346f-8a33-4edb-9397-10394b695173",
           "RepositoryName": "MyRepo",
           "Tags": []
       }
   }
   ```

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