View a markdown version of this page

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

使用 AWS CLI 的 Amazon EMR on EKS 示例

以下代码示例演示如何通过将 AWS Command Line Interface与 Amazon EMR on EKS 结合使用,来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 create-role-associations。

AWS CLI

创建 IAM 角色与 EMR 服务账户的角色关联,以便用于 EKS 上的 Amazon EMR

以下 create-role-associations 示例命令创建名为 example_iam_role 的角色与 EMR 服务账户的 EKS 容器组身份关联,这样便可以在 Amazon EMR on EKS 上,将其用于名为 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 容器组身份关联,这样便可以在 Amazon EMR on EKS 上,将其从名为 example_cluster 的 EKS 集群的 example_namespace 命名空间中移除:

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 的角色的信任策略,以便它可以与名为 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.