AWS CLI を使用した Amazon EMR on EKS の例
次のコード例は、Amazon EMR on EKS で AWS Command Line Interfaceを使用してアクションを実行し、一般的なシナリオを実装する方法を示しています。
アクションはより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。
各例には完全なソースコードへのリンクが含まれており、コードの設定方法と実行方法に関する手順を確認できます。
トピック
アクション
次の例は、create-role-associations を使用する方法を説明しています。
- AWS CLI
-
IAM ロールと Amazon EMR on EKS で使用する EMR サービスアカウントとのロールの関連付けを作成するには
次の
create-role-associationsのコマンド例では、example_iam_role という名前のロールと EMR サービスアカウントとの EKS Pod Identity の関連付けを作成します。これにより、example_cluster という名前の EKS クラスターの example_namespace 名前空間を使用する Amazon EMR on EKS でこのロールを使用できるようになります。aws emr-containers create-role-associations \ --cluster-nameexample_cluster\ --namespaceexample_namespace\ --role-nameexample_iam_role出力:
[ { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-client-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/a-bgyr1umgdmrk1kdtq", "associationId": "a-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" }, { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-driver-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/b-bgyr1umgdmrk1kdtq", "associationId": "b-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" }, { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-executor-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/c-bgyr1umgdmrk1kdtq", "associationId": "c-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" } ]-
API の詳細については、「AWS CLI コマンドリファレンス」の「CreateRoleAssociations
」を参照してください。
-
次の例は、delete-role-associations を使用する方法を説明しています。
- AWS CLI
-
IAM ロールと EMR サービスアカウントとのロールの関連付けを削除するには
EKS は存在しないリソース (名前空間、サービスアカウント) との関連付けを許可するため、EMR on EKS では、名前空間が削除された場合やロールが使用されていない場合に関連付けを削除して、他の関連付けのためのスペースを確保することが推奨されます。
次の
delete-role-associationsのコマンド例では、example_iam_role という名前のロールと EMR サービスアカウントとの EKS Pod Identity の関連付けを削除します。これにより、example_cluster という名前の EKS クラスターの example_namespace 名前空間を使用する Amazon EMR on EKS からこのロールを削除できます。aws emr-containers delete-role-associations \ --cluster-nameexample_cluster\ --namespaceexample_namespace\ --role-nameexample_iam_role出力:
[ { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-client-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/a-bgyr1umgdmrk1kdtq", "associationId": "a-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" }, { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-driver-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/b-bgyr1umgdmrk1kdtq", "associationId": "b-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" }, { "clusterName": "example_cluster", "namespace": "example_namespace", "serviceAccount": "emr-spark-executor-service-account-example", "roleArn": "arn:aws:iam::111111111111:role/example_iam_role", "associationArn": "arn:aws:eks:us-east-1:111111111111:podidentityassociation/example_cluster/c-bgyr1umgdmrk1kdtq", "associationId": "c-bgyr1umgdmrk1kdtq", "tags": {}, "createdAt": "2022-11-15T10:49:00+00:00", "modifiedAt": "2022-11-15T10:49:00+00:00" } ]-
API の詳細については、「AWS CLI コマンドリファレンス」の「DeleteRoleAssociations
」を参照してください。
-
次の例は、update-role-trust-policy を使用する方法を説明しています。
- AWS CLI
-
Amazon EMR on EKS で使用する IAM ロールの信頼ポリシーを更新するには
このコマンド例では、example_iam_role という名前のロールの信頼ポリシーを更新して、example_cluster という名前の EKS クラスターの example_namespace 名前空間で Amazon EMR on EKS で使用できるようにします。
コマンド:
aws emr-containers update-role-trust-policy \ --cluster example_cluster \ --namespace example_namespace \ --role-name example_iam_role出力:
If the trust policy has already been updated, then the output will be: Trust policy statement already exists for role example_iam_role. No changes were made! If the trust policy has not been updated yet, then the output will be: Successfully updated trust policy of role example_iam_role.-
API の詳細については、「AWS CLI コマンドリファレンス」の「UpdateRoleTrustPolicy
」を参照してください。
-