本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
將不同 AWS 帳戶中的 CodeCommit 儲存庫與筆記本執行個體建立關聯
若要將不同 AWS 帳戶中的 CodeCommit 儲存庫與您的筆記本執行個體建立關聯,請設定 CodeCommit 儲存庫的跨帳戶存取權。
若要為 CodeCommit 儲存庫設定跨帳戶存取權,請將其與筆記本執行個體建立關聯:
-
在包含 CodeCommit 儲存庫的 AWS 帳戶中,建立 IAM 政策,允許包含筆記本執行個體的帳戶中的使用者存取儲存庫。如需相關資訊,請參閱步驟 1:在 AccountA 中建立儲存庫存取權政策在 CodeCommit 使用者指南。
-
在包含 CodeCommit 儲存庫的 AWS 帳戶中,建立 IAM 角色,並將您在上一個步驟中建立的政策連接到該角色。如需相關資訊,請參閱步驟 2:在 AccountA 中為儲存庫存取權建立角色,在 CodeCommit 使用者指南。
-
在使用您在上個步驟中建立之角色的筆記本執行個體中建立設定檔:
-
開啟筆記本執行個體。
-
在筆記本執行個體開啟終端機。
-
透過在終端機輸入以下內容來編輯新的設定檔:
vi /home/ec2-user/.aws/config
-
使用以下設定檔資訊來編輯檔案:
[profile
CrossAccountAccessProfile
] region = us-west-2 role_arn = arn:aws:iam::CodeCommitAccount
:role/CrossAccountRepositoryContributorRole
credential_source=Ec2InstanceMetadata output = json其中
CodeCommitAccount
是包含 CodeCommit 儲存庫的帳戶,CrossAccountAccessProfile
是新設定檔的名稱,而CrossAccountRepositoryContributorRole
是您在上個步驟建立的角色名稱。
-
-
在筆記本執行個體中,將 git 設定為使用您在上個步驟中建立的設定檔:
-
開啟筆記本執行個體。
-
在筆記本執行個體開啟終端機。
-
在終端機中輸入以下內容來編輯 Git 組態檔案:
vi /home/ec2-user/.gitconfig
-
使用以下設定檔資訊來編輯檔案:
[credential] helper = !aws codecommit credential-helper --profile
CrossAccountAccessProfile
$@ UseHttpPath = true其中
CrossAccountAccessProfile
是您在上個步驟建立的設定檔名稱。
-