

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

# カスタム AMI を使用したクラスター管理
<a name="hyperpod-custom-ami-cluster-management"></a>

カスタム AMI を構築したら、Amazon SageMaker HyperPod クラスターの作成または更新に使用できます。新しい AMI を使用するインスタンスグループをスケールアップまたは追加することもできます。

## クラスターオペレーションに必要なアクセス許可
<a name="hyperpod-custom-ami-permissions"></a>

SageMaker HyperPod クラスターを操作して設定するクラスター管理者ユーザーに、以下のアクセス許可を追加します。次のポリシー例には、クラスター管理者が SageMaker HyperPod コア API、 アカウント内で SageMaker HyperPod クラスターを管理するための最小限のアクセス許可のセットが含まれています。

AMI および AMI EBS スナップショット共有アクセス許可は、次のポリシーの一部として `ModifyImageAttribute` API アクセス許可および `ModifySnapshotAttribute` API アクセス許可を介して含まれることに注意が必要です。共有アクセス許可の範囲を絞り込むには、次の手順を実行します。
+ AMI および AMI スナップショットへの AMI 共有アクセス許可を制御するタグを追加します。例えば、AMI に `AllowSharing` を `true` としてタグ付けできます。
+ ポリシーにコンテキストキーを追加して、特定のタグでタグ付けされた AMI のみに AMI 共有を許可できます。

次のポリシーは、`AllowSharing` が `true` であるタグを付けられた AMI のみが許可されるようにスコープダウンされたポリシーです。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "iam:PassRole",
            "Resource": "arn:aws:iam::111122223333:role/your-execution-role-name"
        },
        {
            "Effect": "Allow",
            "Action": [
                "sagemaker:CreateCluster",
                "sagemaker:DeleteCluster",
                "sagemaker:DescribeCluster",
                "sagemaker:DescribeClusterNode",
                "sagemaker:ListClusterNodes",
                "sagemaker:ListClusters",
                "sagemaker:UpdateCluster",
                "sagemaker:UpdateClusterSoftware",
                "sagemaker:BatchDeleteClusterNodes",
                "eks:DescribeCluster",
                "eks:CreateAccessEntry",
                "eks:DescribeAccessEntry",
                "eks:DeleteAccessEntry",
                "eks:AssociateAccessPolicy",
                "iam:CreateServiceLinkedRole",
                "ec2:DescribeImages",
                "ec2:DescribeSnapshots"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:ModifyImageAttribute",
                "ec2:ModifySnapshotAttribute"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/AllowSharing": "true"
                }
            }
        }
    ]
}
```

------

**重要**  
暗号化されたカスタム AMI を使用する場合は、KMS キーが「[SageMaker HyperPod のカスタマーマネージド AWS KMS key 暗号化](smcluster-cmk.md)」で説明されているアクセス許可を満たしていることを確認してください。さらに、カスタム AMI の KMS キーがクラスターの Amazon EBS ルートボリュームの暗号化にも使用されていることを確認します。

## クラスターを作成する
<a name="hyperpod-custom-ami-api-create"></a>

`CreateCluster` オペレーションの `ImageId` フィールドでカスタム AMI を指定できます。

次の例は、クラスターボリュームを暗号化するための AWS KMS カスタマーマネージドキーの有無にかかわらず、カスタム AMI を使用してクラスターを作成する方法を示しています。

------
#### [ Standard example ]

次の例は、カスタム AMI を使用してクラスターを作成する方法を説明しています。

```
aws sagemaker create-cluster \
   --cluster-name <exampleClusterName> \
   --orchestrator 'Eks={ClusterArn='<eks_cluster_arn>'}' \
   --node-provisioning-mode Continuous \
   --instance-groups '{
   "InstanceGroupName": "<exampleGroupName>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 2,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ImageId": "<your_custom_ami>",
   "ExecutionRole": "<arn:aws:iam::444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "InstanceStorageConfigs": [
   
        {
            "EbsVolumeConfig": {
                "VolumeSizeInGB": 200
            }
        }
   ]
}' --vpc-config '{
   "SecurityGroupIds": ["<security_group>"],
   "Subnets": ["<subnet>"]
}'
```

------
#### [ Customer managed key example ]

次の例は、クラスターの Amazon EBS ボリュームを暗号化するための独自の AWS KMS カスタマーマネージドキーを指定しながら、カスタム AMI を使用してクラスターを作成する方法を示しています。ルートボリュームとインスタンスストレージボリュームに異なるカスタマーマネージドキーを指定できます。`InstanceStorageConfigs` フィールドでカスタマーマネージドキーを使用しない場合、 AWS 所有の KMS キーを使用してボリュームを暗号化します。ルートボリュームとセカンダリインスタンスストレージボリュームに異なるキーを使用する場合は、両方のキーに必要な KMS キーポリシーを設定します。

```
aws sagemaker create-cluster \
   --cluster-name <exampleClusterName> \
   --orchestrator 'Eks={ClusterArn='<eks_cluster_arn>'}' \
   --node-provisioning-mode Continuous \
   --instance-groups '{
   "InstanceGroupName": "<exampleGroupName>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 2,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ImageId": "<your_custom_ami>",
   "ExecutionRole": "<arn:aws:iam:us-east-1:444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "InstanceStorageConfigs": [
             # Root volume configuration
            {
                "EbsVolumeConfig": {
                    "RootVolume": True,
                    "VolumeKmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/key-id"
                }
            },
            # Instance storage volume configuration
            {
                "EbsVolumeConfig": {
                    "VolumeSizeInGB": 100,
                    "VolumeKmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/key-id"
                }
            }
   ]
}' --vpc-config '{
   "SecurityGroupIds": ["<security_group>"],
   "Subnets": ["<subnet>"]
}'
```

------

## クラスターのソフトウェアをアップデートする
<a name="hyperpod-custom-ami-api-update"></a>

クラスター上の既存のインスタンスグループをカスタム AMI で更新する場合は、`UpdateClusterSoftware` オペレーションを使用し、`ImageId` フィールドにカスタム AMI を指定します。リクエストで特定のインスタンスグループの名前を指定しない限り、新しいイメージはクラスター内のすべてのインスタンスグループに適用されることに注意が必要です。

次の例は、カスタム AMI を使用してクラスターのプラットフォームソフトウェアを更新する方法を説明しています。

```
aws sagemaker update-cluster-software \
   --cluster-name <exampleClusterName> \
   --instance-groups <instanceGroupToUpdate> \
   --image-id <customAmiId>
```

## インスタンスグループをスケールアップする
<a name="hyperpod-custom-ami-scale-up"></a>

次の例は、暗号化に AWS KMS カスタマーマネージドキーを使用するかどうかにかかわらず、カスタム AMI を使用してクラスターのインスタンスグループをスケールアップする方法を示しています。

------
#### [ Standard example ]

次の例は、カスタム AMI を使用してインスタンスグループをスケールアップする方法を説明しています。

```
aws sagemaker update-cluster \
    --cluster-name <exampleClusterName> --instance-groups '[{                  
    "InstanceGroupName": "<exampleGroupName>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 2,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ExecutionRole": "<arn:aws:iam::444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "ImageId": "<your_custom_ami>"
}]'
```

------
#### [ Customer managed key example ]

次の例は、クラスターの Amazon EBS ボリュームを暗号化するための独自の AWS KMS カスタマーマネージドキーを指定しながら、カスタム AMI を使用してクラスターを更新およびスケールアップする方法を示しています。ルートボリュームとインスタンスストレージボリュームに異なるカスタマーマネージドキーを指定できます。`InstanceStorageConfigs` フィールドでカスタマーマネージドキーを使用しない場合、 AWS 所有の KMS キーを使用してボリュームを暗号化します。ルートボリュームとセカンダリインスタンスストレージボリュームに異なるキーを使用する場合は、両方のキーに必要な KMS キーポリシーを設定します。

```
aws sagemaker update-cluster \
    --cluster-name <exampleClusterName> --instance-groups '[{                  
    "InstanceGroupName": "<exampleGroupName>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 2,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ExecutionRole": "<arn:aws:iam::444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "ImageId": "<your_custom_ami>",
   "InstanceStorageConfigs": [
             # Root volume configuration
            {
                "EbsVolumeConfig": {
                    "RootVolume": True,
                    "VolumeKmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/key-id"
                }
            },
            # Instance storage volume configuration
            {
                "EbsVolumeConfig": {
                    "VolumeSizeInGB": 100,
                    "VolumeKmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/key-id"
                }
            }
   ]
}]'
```

------

## 新しいインスタンスグループを追加する
<a name="hyperpod-custom-ami-add-instance-group"></a>

次の例は、カスタム AMI を使用してクラスターにインスタンスグループを追加する方法を説明しています。

```
aws sagemaker update-cluster \
   --cluster-name "<exampleClusterName>" \
   --instance-groups '{
   "InstanceGroupName": "<exampleGroupName>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 2,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ExecutionRole": "<arn:aws:iam::444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "ImageId": "<your_custom_ami>"
}' '{
   "InstanceGroupName": "<exampleGroupName2>",
   "InstanceType": "ml.c5.2xlarge",
   "InstanceCount": 1,
   "LifeCycleConfig": {
      "SourceS3Uri": "<s3://amzn-s3-demo-bucket>",
      "OnCreate": "on_create_noop.sh"
   },
   "ExecutionRole": "<arn:aws:iam::444455556666:role/Admin>",
   "ThreadsPerCore": 1,
   "ImageId": "<your_custom_ami>"
}'
```