View a markdown version of this page

使用 的 Amazon EMR on EKS 範例 AWS CLI - AWS Command Line Interface

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

使用 的 Amazon EMR on EKS 範例 AWS CLI

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Amazon EMR on EKS 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結,您可在連結中找到如何設定和執行內容中程式碼的相關指示。

主題

動作

以下程式碼範例顯示如何使用 create-role-associations。

AWS CLI

建立 IAM 角色與 EMR 服務帳戶的角色關聯,以便與 Amazon EMR on EKS 搭配使用

下列create-role-associations範例命令會建立名為 example_iam_role 之角色的 EKS Pod 身分關聯與 EMR 服務帳戶,以便與名為 example_cluster 之 EKS 叢集的 example_namespace 命名空間搭配使用:

aws emr-containers create-role-associations \ --cluster-name example_cluster \ --namespace example_namespace \ --role-name example_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" } ]

以下程式碼範例顯示如何使用 delete-role-associations。

AWS CLI

刪除 IAM 角色與 EMR 服務帳戶的角色關聯

EKS 允許與非現有資源 (命名空間、服務帳戶) 的關聯,因此 EMR on EKS 建議在刪除命名空間或角色未使用 釋出其他關聯的空間時刪除關聯。

下列delete-role-associations範例命令會刪除名為 example_iam_role 之角色與 EMR 服務帳戶的 EKS Pod 身分關聯,以便從名為 example_cluster 之 EKS 叢集的 Amazon EMR on EKS 中移除它:

aws emr-containers delete-role-associations \ --cluster-name example_cluster \ --namespace example_namespace \ --role-name example_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" } ]

以下程式碼範例顯示如何使用 update-role-trust-policy。

AWS CLI

更新要與 Amazon EMR on EKS 搭配使用之 IAM 角色的信任政策

此範例命令會更新名為 example_iam_role 之角色的信任政策,以便與 EKS 上的 Amazon EMR (其中具有來自名為 example_cluster 之 EKS 叢集的 example_namespace 命名空間) 搭配使用。

命令:

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.