

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