

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# ある の AWS CodeCommit リポジトリ AWS アカウント を別のアカウントの Amazon SageMaker AI Studio Classic に関連付ける
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account"></a>

*Amazon Web Services、Laurens van der Maas,Aubrey Oosthuizen*

## 概要
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-summary"></a>

このパターンでは、ある AWS アカウント (アカウント A) の AWS CodeCommit リポジトリを別の ( AWS アカウント アカウント B) の Amazon SageMaker AI Studio Classic に関連付ける方法の手順とコードを示します。関連付けを設定するには、アカウント A に AWS Identity and Access Management (IAM) ポリシーとロールを作成し、アカウント B に IAM インラインポリシーを作成する必要があります。次に、シェルスクリプトを使用して、アカウント A からアカウント B の Amazon SageMaker AI Classic に CodeCommit リポジトリをクローンします。

## 前提条件と制限事項
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-prereqs"></a>

**前提条件**
+ 2 つの [AWS アカウント](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/)のうち 1 つには CodeCommit リポジトリが、もう 1 つにはユーザーの SageMaker AI ドメインが含まれていること
+ プロビジョニングされた [SageMaker AI ドメインとユーザー](https://docs.aws.amazon.com/sagemaker/latest/dg/gs-studio-onboard.html)、インターネットアクセスまたは仮想プライベートネットワーク (VPC AWS STS) エンドポイントを介した CodeCommit および AWS Security Token Service () へのアクセス
+ 「[IAM](https://docs.aws.amazon.com/iam/?id=docs_gateway)」の基本的な理解
+ [SageMaker AI Studio Classic](https://docs.aws.amazon.com/sagemaker/latest/dg/studio.html) の基本的な理解
+ [Git](https://git-scm.com/) と [CodeCommit](https://docs.aws.amazon.com/codecommit/index.html) に関する基本的な知識

**制限事項**

このパターンは SageMaker AI Studio Classic にのみ適用され、RStudio on Amazon SageMaker AI には適用されません。

## アーキテクチャ
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-architecture"></a>

**テクノロジースタック**
+ Amazon SageMaker AI
+ Amazon SageMaker AI Studio Classic
+ AWS CodeCommit
+ AWS Identity and Access Management (IAM) 
+ Git

**ターゲットアーキテクチャ**

以下の図は、アカウント A の CodeCommit リポジトリをアカウント B の SageMaker AI Studio Classic に関連付けるアーキテクチャを示したものです。

![\[クロスアカウント関連付けのアーキテクチャ図\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/images/pattern-img/d40df9eb-6ee2-4cb8-8257-051fa624e52a/images/abb89a66-fc8f-4e72-8f45-f0f44c2ec6ce.png)


この図表は、次のワークフローを示しています:

1. ユーザーはアカウント A の `sts:AssumeRole` ロールを通じてアカウント A の `MyCrossAccountRepositoryContributorRole` ロールを引き受け、アカウント B の SageMaker AI Studio Classic で SageMaker AI 実行ロールを使用します。引き受けたロールには、指定されたリポジトリをクローンして操作するための CodeCommit 権限が含まれています。

1. ユーザーは Git コマンドを SageMaker AI Studio Classic のシステムターミナルから実行します。

**自動化とスケール**

このパターンは、[AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/?id=docs_gateway)、[AWS CloudFormation](https://docs.aws.amazon.com/cloudformation/?id=docs_gateway)、[Terraform](https://www.terraform.io/) のいずれかを使用することで自動化できる手動のステップで構成されています。

## ツール
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-tools"></a>

**AWS ツール**
+ [Amazon SageMaker AI](https://docs.aws.amazon.com/sagemaker/?id=docs_gateway) はマネージド型の機械学習 (ML) サービスで、ML モデルの構築とトレーニングを行い、それらを本番稼働環境に対応したホスティング環境にデプロイします。
+ [Amazon SageMaker AI Studio Classic](https://docs.aws.amazon.com/sagemaker/latest/dg/studio.html) は、ウェブベースの機械学習用の統合開発環境 (IDE) です。この IDE を使うと、機械学習モデルを構築、トレーニング、デバッグ、デプロイ、モニタリングできます。
+ [AWS CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html) は、独自のソースコントロールシステムを管理しなくても、Git リポジトリを非公開で保存および管理できるバージョン管理サービスです。

  **注意**: AWS CodeCommit は新規顧客には利用できなくなりました。の既存のお客様は、通常どおりサービスを AWS CodeCommit 引き続き使用できます。[詳細はこちら](https://aws.amazon.com/blogs/devops/how-to-migrate-your-aws-codecommit-repository-to-another-git-provider/)
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) は、誰を認証し、誰に使用する権限を付与するかを制御することで、 AWS リソースへのアクセスを安全に管理するのに役立ちます。

**その他のツール**
+ 「[Git](https://git-scm.com/)」は、ソフトウェア開発中のソースコードの変更を追跡するための分散型バージョン管理システムです。

## エピック
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-epics"></a>

### アカウント A で IAM ポリシーと IAM ロールを作成
<a name="create-an-iam-policy-and-iam-role-in-account-a"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| Account A でリポジトリアクセスの IAM ポリシーを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account.html)IAM ポリシーの範囲をユースケースに最低限必要なアクセス権限に制限するのがベストプラクティスです。 | AWS DevOps | 
| Account A でリポジトリアクセスの IAM ロールを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account.html) | AWS DevOps | 

### アカウント B で IAM インラインポリシーを作成します。
<a name="create-an-iam-inline-policy-in-account-b"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| アカウント B の SageMaker ドメインユーザーにアタッチされている実行ロールにインラインポリシーをアタッチします。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account.html) | AWS DevOps | 

### SageMaker AI Studio Classic のリポジトリをアカウント B 用にクローンします。
<a name="clone-the-repository-in-sm-studio-classic-for-account-b"></a>


| タスク | 説明 | 必要なスキル | 
| --- | --- | --- | 
| アカウント B の SageMaker AI Studio Classic でシェルスクリプトを作成します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account.html) | AWS DevOps | 
| システムターミナルからシェルスクリプトを呼び出します。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account.html)SageMaker AI Studio Classic のクロスアカウントで CodeCommit リポジトリのクローンが作成されました。システムターミナルからすべての Git コマンドを実行できるようになりました。 | AWS DevOps | 

## 追加情報
<a name="associate-an-aws-codecommit-repository-in-one-aws-account-with-sagemaker-studio-in-another-account-additional"></a>

**IAM ポリシーの例**

この例のポリシーを使用するには、次を行います。
+ をリポジトリ AWS リージョン の `<CodeCommit_Repository_Region>`に置き換えます。
+ アカウント A のアカウント ID で `<Account_A_ID>` を置き換えます。
+ アカウント A の CodeCommit リポジトリの名前に `<CodeCommit_Repository_Name>` 置き換えてください。

```
{
"Version": "2012-10-17",		 	 	 
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "codecommit:BatchGet*",
            "codecommit:Create*",
            "codecommit:DeleteBranch",
            "codecommit:Get*",
            "codecommit:List*",
            "codecommit:Describe*",
            "codecommit:Put*",
            "codecommit:Post*",
            "codecommit:Merge*",
            "codecommit:Test*",
            "codecommit:Update*",
            "codecommit:GitPull",
            "codecommit:GitPush"
        ],
        "Resource": [
            "arn:aws:codecommit:<CodeCommit_Repository_Region>:<Account_A_ID>:<CodeCommit_Repository_Name>"
        ]
    }
]
}
```

**SageMaker AI シェルスクリプトの例**

この例のスクリプトを使用するには、次を行います。
+ アカウント A のアカウント ID で `<Account_A_ID>` を置き換えます。
+ 前に作成した IAM ロールの名前で `<Account_A_Role_Name>` を置き換えます。
+ をリポジトリ AWS リージョン の `<CodeCommit_Repository_Region>`に置き換えます。
+ アカウント A の CodeCommit リポジトリの名前に `<CodeCommit_Repository_Name>` を置き換えてください。

```
#!/usr/bin/env bash
#Launch from system terminal
pip install --quiet git-remote-codecommit

mkdir -p ~/.aws
touch ~/.aws/config

echo "[profile CrossAccountAccessProfile]
region = <CodeCommit_Repository_Region>
credential_source=EcsContainer
role_arn = arn:aws:iam::<Account_A_ID>:role/<Account_A_Role_Name>
output = json" > ~/.aws/config

echo '[credential "https://git-codecommit.<CodeCommit_Repository_Region>.amazonaws.com"]
        helper = !aws codecommit credential-helper $@ --profile CrossAccountAccessProfile
        UseHttpPath = true' > ~/.gitconfig
        
git clone codecommit::<CodeCommit_Repository_Region>://CrossAccountAccessProfile@<CodeCommit_Repository_Name>
```