

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS CodeCommit 使用 git-remote-codecommit 對 HTTPS 連線的設定步驟
<a name="setting-up-git-remote-codecommit"></a>

如果您想要使用根帳戶、聯合存取或暫時登入資料連線至 CodeCommit，您應該使用 設定存取**git-remote-codecommit**。此公用程式提供簡單的方法，可透過擴展 Git 從 CodeCommit 儲存庫推送和提取程式碼。這是支援使用聯合存取、身分提供者和臨時登入資料進行連線的建議方法。若要將許可指派給聯合身分，您可以建立角色並定義角色的許可。當聯合身分進行身分驗證時，該身分會與角色建立關聯，並獲授予由角色定義的許可。如需有關聯合角色的相關資訊，請參閱《*IAM 使用者指南*》中的[為第三方身分提供者 (聯合) 建立角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp.html)。如果您使用 IAM Identity Center，則需要設定許可集。為控制身分驗證後可以存取的內容，IAM Identity Center 將許可集與 IAM 中的角色相關聯。如需有關許可集的資訊，請參閱《*AWS IAM Identity Center 使用者指南*》中的[許可集](https://docs.aws.amazon.com/singlesignon/latest/userguide/permissionsetsconcept.html)。

您也可以**git-remote-codecommit**搭配 IAM 使用者使用 。**git-remote-codecommit** 與其他 HTTPS 連線方法不同，不需要為使用者設定 Git 登入資料。

**注意**  
某些 IDE 不支援 `git-remote-codecommit` 使用的複製 URL 格式。您可能必須先將儲存庫手動複製到本機電腦，才能在偏好使用的 IDE 中使用這些儲存庫。如需詳細資訊，請參閱[對 git-remote-codecommit 和 進行故障診斷 AWS CodeCommit](troubleshooting-grc.md)。

這些程序的編寫假設您擁有 Amazon Web Services 帳戶、已在 CodeCommit 中建立至少一個儲存庫，並在連線至 CodeCommit 儲存庫時使用具有受管政策的 IAM 使用者。如需如何為聯合身分使用者設定存取和其他輪換登入資料類型的相關資訊，請參閱[使用輪換憑證連線至 AWS CodeCommit 儲存庫](temporary-access.md)。

**Topics**
+ [步驟 0：安裝 git-remote-codecommit 的先決條件](#setting-up-git-remote-codecommit-prereq)
+ [步驟 1：CodeCommit 的初始組態](#setting-up-git-remote-codecommit-account)
+ [步驟 2：安裝 git-remote-codecommit](#setting-up-git-remote-codecommit-install)
+ [步驟 3：連線至 CodeCommit 主控台並複製儲存庫](#setting-up-git-remote-codecommit-connect-console)
+ [後續步驟](#setting-up-git-remote-codecommit-next-step)

## 步驟 0：安裝 git-remote-codecommit 的先決條件
<a name="setting-up-git-remote-codecommit-prereq"></a>

您必須先在本機電腦上安裝某些必要項目，才能使用 **git-remote-codecommit**。其中包含：
+ 支援的 Python 版本。如需 Python 支援版本的詳細資訊，請參閱 [git-remote-codecommit](https://pypi.org/project/git-remote-codecommit/)。

  如需設定和使用 git-remote-codecommit 的詳細資訊，請參閱 [AWS CodeCommit 使用 git-remote-codecommit 對 HTTPS 連線的設定步驟](#setting-up-git-remote-codecommit)。
+ Git

**注意**  
當您在 Windows 上安裝 Python 時，請務必選擇此選項以將 Python 新增到路徑中。

**git-remote-codecommit** 需要 PIP 9.0.3 版或更新版本。若要檢查您的 PIP 版本，請開啟終端機或命令列，然後執行下列命令：

```
pip --version
```

您可以執行下列兩個命令，將 PIP 版本更新為最新版：

```
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py --user
```

若要使用 CodeCommit 儲存庫中的檔案、遞交和其他資訊，您必須在本機電腦上安裝 Git。CodeCommit 支援 Git 1.7.9 版和更新版本。Git 2.28 版支援為初始遞交設定分支名稱。我們建議您使用最新版本的 Git。

若要安裝 Git，我們建議使用 [Git Downloads](http://git-scm.com/downloads) 等網站。

**注意**  
Git 是一個不斷發展、定期更新的平台。有時，功能變更可能會影響其使用 CodeCommit 的方式。如果您遇到 Git 和 CodeCommit 特定版本的問題，請檢閱 中的資訊[疑難排解](troubleshooting.md)。

## 步驟 1：CodeCommit 的初始組態
<a name="setting-up-git-remote-codecommit-account"></a>

請依照下列步驟建立 IAM 使用者、使用適當的政策進行設定、取得存取金鑰和私密金鑰，以及安裝和設定 AWS CLI。

**建立和設定 IAM 使用者以存取 CodeCommit**

1. 前往 https：//[http://aws.amazon.com](https://aws.amazon.com/) 並選擇**註冊**來建立 Amazon Web Services 帳戶。

1. 在您的 Amazon Web Services 帳戶中建立 IAM 使用者，或使用現有的使用者。請確定您擁有與該 IAM 使用者相關聯的存取金鑰 ID 和私密存取金鑰。如需詳細資訊，請參閱[在您的 Amazon Web Services 帳戶中建立 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_SettingUpUser.html)。
**注意**  
CodeCommit 需要 AWS Key Management Service。如果您使用的是現有的 IAM 使用者，請確定沒有政策連接到明確拒絕 CodeCommit 所需的 AWS KMS 動作的使用者。如需詳細資訊，請參閱[AWS KMS 和 加密](encryption.md)。

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在 IAM 主控台的導覽窗格中，選擇**使用者**，然後選擇您要為 CodeCommit 存取設定的 IAM 使用者。

1. 在 **Permissions (許可)** 標籤上，選擇 **Add Permissions (新增許可)**。

1. 在 **Grant permissions (授予許可)** 中，選擇 **Attach existing policies directly (直接連接現有政策)**。

1. 從政策清單中，選取 **AWSCodeCommitPowerUser** 或其他 CodeCommit 存取的受管政策。如需詳細資訊，請參閱[AWS CodeCommit 的 受管政策](security-iam-awsmanpol.md)。

   選取要連接的政策之後，請選擇**下一步：檢閱**以檢閱要連接到 IAM 使用者的政策清單。如果清單正確，請選擇 **Add permissions (新增許可)**。

    如需 CodeCommit 受管政策以及與其他群組和使用者共用儲存庫存取權的詳細資訊，請參閱 [共用儲存庫](how-to-share-repository.md)和 [的身分驗證和存取控制 AWS CodeCommit](auth-and-access-control.md)。

**安裝和設定 AWS CLI**

1. 在本機電腦上，下載並安裝 AWS CLI。這是從命令列與 CodeCommit 互動的先決條件。我們建議您安裝 AWS CLI 第 2 版。這是 的最新主要版本， AWS CLI 並支援所有最新功能。這是 唯一 AWS CLI 支援搭配 使用根帳戶、聯合存取或臨時憑證的 版本**git-remote-codecommit**。

   如需詳細資訊，請參閱[使用 AWS 命令列界面進行設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html)。
**注意**  
CodeCommit 僅適用於 1.7.38 版和更新 AWS CLI 版本。最佳實務是安裝 或 AWS CLI 將 升級至可用的最新版本。若要判斷 AWS CLI 您已安裝的 版本，請執行 **aws --version**命令。  
若要 AWS CLI 將舊版 升級至最新版本，請參閱[安裝 AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)。

1. 執行此命令，以確認 AWS CLI 已安裝 的 CodeCommit 命令。

   ```
   aws codecommit help
   ```

   此命令會傳回 CodeCommit 命令的清單。

1. 使用 **configure**命令 AWS CLI 以設定檔設定 ，如下所示：

   ```
   aws configure
   ```

   出現提示時，請指定要與 CodeCommit 搭配使用之 IAM 使用者的 AWS 存取金鑰和 AWS 私密存取金鑰。此外，請務必指定儲存 AWS 區域 庫所在的 ，例如 `us-east-2`。系統提示您輸入預設輸出格式時，請指定 `json`。例如，如果您為 IAM 使用者設定設定檔：

   ```
   AWS Access Key ID [None]: Type your IAM user AWS access key ID here, and then press Enter
   AWS Secret Access Key [None]: Type your IAM user AWS secret access key here, and then press Enter
   Default region name [None]: Type a supported region for CodeCommit here, and then press Enter
   Default output format [None]: Type json here, and then press Enter
   ```

   如需建立和設定設定檔以搭配 使用的詳細資訊 AWS CLI，請參閱下列內容：
   + [命名設定檔](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
   + [在 中使用 IAM 角色 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html)
   + [設定命令](https://docs.aws.amazon.com/cli/latest/reference/set.html)
   + [使用輪換憑證連線至 AWS CodeCommit 儲存庫](temporary-access.md)

   若要連線到儲存庫或其他資源 AWS 區域，您必須 AWS CLI 使用預設區域名稱重新設定 。CodeCommit 支援的預設區域名稱包括：
   + us-east-2
   + us-east-1
   + eu-west-1
   + us-west-2
   + ap-northeast-1
   + ap-southeast-1
   + ap-southeast-2
   + ap-southeast-3
   + me-central-1
   + eu-central-1
   + ap-northeast-2
   + sa-east-1
   + us-west-1
   + eu-west-2
   + ap-south-1
   + ap-south-1
   + ca-central-1
   + us-gov-west-1
   + us-gov-east-1
   + eu-north-1
   + ap-east-1
   + me-south-1
   + cn-north-1
   + cn-northwest-1
   + eu-south-1
   + ap-northeast-3
   + af-south-1
   + il-central-1

   如需 CodeCommit 和 的詳細資訊 AWS 區域，請參閱 [區域和 Git 連線端點](regions.md)。如需 IAM、存取金鑰和私密金鑰的詳細資訊，請參閱[如何取得登入資料？](https://docs.aws.amazon.com/IAM/latest/UserGuide/IAM_Introduction.html#IAM_SecurityCredentials)以及[管理 IAM 使用者的存取金鑰](https://docs.aws.amazon.com/IAM/latest/UserGuide/ManagingCredentials.html)。如需 AWS CLI 和 設定檔的詳細資訊，請參閱[具名設定檔](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)。

## 步驟 2：安裝 git-remote-codecommit
<a name="setting-up-git-remote-codecommit-install"></a>

請按照下列步驟安裝 **git-remote-codecommit**。

**如何安裝 git-remote-codecommit**

1. 在終端機或命令列，執行下列命令：

   ```
   pip install git-remote-codecommit
   ```
**注意**  
根據您的作業系統和組態，您可能需要使用提升的許可執行此命令，例如 sudo，或使用 --user 參數安裝到不需要特殊權限的目錄，例如您目前的使用者帳戶。例如，在執行 Linux、macOS 或 Unix 的電腦上：  

   ```
   sudo pip install git-remote-codecommit
   ```
在執行 Windows 的電腦上：  

   ```
   pip install --user git-remote-codecommit
   ```

1. 監控安裝程序，直到您看到成功訊息為止。

## 步驟 3：連線至 CodeCommit 主控台並複製儲存庫
<a name="setting-up-git-remote-codecommit-connect-console"></a>

如果管理員已將用於 CodeCommit 儲存庫**git-remote-codecommit**的複製 URL 傳送給您，您可以略過連線至主控台並直接複製儲存庫。

**連線至 CodeCommit 儲存庫**

1. 在 https：//[https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home) 開啟 CodeCommit 主控台。

1. 在區域選擇器中，選擇建立儲存庫 AWS 區域 的 。儲存庫專屬於 AWS 區域。如需詳細資訊，請參閱[區域和 Git 連線端點](regions.md)。

1. 尋找您要從清單連接的儲存庫並加以選擇。選擇 **Clone URL (複製 URL)**，然後選擇複製和連線至儲存庫時要使用的通訊協定。這會將複製 URL 複製。
   + 如果您使用 Git 登入資料搭配 IAM 使用者或 隨附的登入資料協助程式，請複製 HTTPS URL AWS CLI。
   + 如果您是在本機電腦上使用 **git-remote-codecommit** 命令，請複製 HTTPS (GRC) URL。
   + 如果您搭配 IAM 使用者使用 SSH 公有/私有金鑰對，請複製 SSH URL。
**注意**  
 如果您看到**歡迎**頁面，而不是儲存庫清單，則在您登入 AWS 區域 的 中，沒有與 AWS 您的帳戶相關聯的儲存庫。要建立儲存庫，請參閱 [建立 AWS CodeCommit 儲存庫](how-to-create-repository.md) 或依照 [Git 和 CodeCommit 入門](getting-started.md) 教學課程中的步驟。

1. 在終端機或命令提示視窗中，使用 **git clone** 命令複製儲存庫。如果您已建立具名 AWS CLI 設定檔，請使用您複製的 HTTPS git-remote-codecommit URL 和設定檔的名稱。如果您沒有指定描述檔，此命令會假定預設描述檔。在您執行此命令的目錄中，將會在該目錄的子目錄中建立本機儲存庫。例如，若要將名為 *MyDemoRepo* 的儲存庫複製到名為 *my-demo-repo* 的本機儲存庫：

   ```
   git clone codecommit://MyDemoRepo my-demo-repo
   ```

   如何使用名為 *CodeCommitProfile* 的描述檔來複製同一個儲存庫：

   ```
   git clone codecommit://CodeCommitProfile@MyDemoRepo my-demo-repo
   ```

   若要複製與設定檔中所設定儲存庫 AWS 區域 不同的儲存庫，請包含 AWS 區域 名稱。例如：

   ```
   git clone codecommit::ap-northeast-1://MyDemoRepo my-demo-repo
   ```

## 後續步驟
<a name="setting-up-git-remote-codecommit-next-step"></a>

您已完成事前準備。依照中的步驟[開始使用 CodeCommit ](getting-started-cc.md)開始使用 CodeCommit。

若要了解如何建立和推送您的第一個遞交，請參閱 [在 中建立遞交 AWS CodeCommit](how-to-create-commit.md)。如果您是初次使用 Git，您可能還需要檢閱[我可以在哪裡進一步了解 Git？](welcome.md#welcome-get-started-with-git)和[Git 和 入門 AWS CodeCommit](getting-started.md)中的資訊。