【问题标题】:Unable to create Aws Emr Cluster using Java Sdk无法使用 Java Sdk 创建 Aws Emr 集群
【发布时间】:2019-10-24 11:05:42
【问题描述】:

我正在使用 Java SDK(下面是代码 sn-p)启动一个 AWS ERM 集群,它工作得非常好。

BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKeyId, secretAccessKeyId);
AmazonElasticMapReduce emrClient = AmazonElasticMapReduceClientBuilder.standard()
                    .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                    .withRegion(region)
                    .build();

JobFlowInstancesConfig jobFlowInstanceConfig = new JobFlowInstancesConfig()
                .withEc2SubnetId("subnetId")
                .withEc2KeyName("ec2KeyName") 
                .withInstanceCount(3) 
                .withKeepJobFlowAliveWhenNoSteps(true)    
                .withMasterInstanceType(c5.4xlarge)
                .withSlaveInstanceType(c5.4xlarge); 


        // create the cluster
        RunJobFlowRequest request = new RunJobFlowRequest()
                .withName("clusterName")
                .withReleaseLabel("emr-5.23.0")
                .withApplications("<Added following in applications Hadoop,Spark,Ganglia,Zeppelin>")
                .withLogUri("s3 path")
                .withServiceRole("EMR_DefaultRole")
                .withJobFlowRole("EMR_EC2_DefaultRole")
                .withInstances(jobFlowInstanceConfig);

RunJobFlowResult runJobFlowResult = emrClient.runJobFlow(request); 

稍后在另一个 AWS 环境中,我们的 AWS 团队创建了一个角色,用于从特定的 EC2 实例创建集群。但我无法创建集群。 下面是带有附加配置的代码 sn-p,以及我注意到的与我之前的配置相关的更改。

  1. 没有 accessKeyId 和 secretAccessKeyId
  2. EMR_EC2_DefaultRole 更改为配置的角色
  3. 添加了安全配置

    AmazonElasticMapReduce emrClient = AmazonElasticMapReduceClientBuilder.standard()
                    .withRegion(region)
                    .build();
    
    JobFlowInstancesConfig jobFlowInstanceConfig = new JobFlowInstancesConfig()
                .withEc2SubnetId("subnetId")
                .withEc2KeyName("ec2KeyName") 
                .withInstanceCount(3) 
                .withKeepJobFlowAliveWhenNoSteps(true)    
                .withMasterInstanceType(c5.4xlarge)
                .withSlaveInstanceType(c5.4xlarge); 
    
    RunJobFlowRequest request = new RunJobFlowRequest()
                .withName("clusterName")
                .withReleaseLabel("emr-5.23.0")
                .withApplications("<Added following in applications Hadoop,Spark,Ganglia,Zeppelin>")
                .withLogUri("s3 path")
                .withServiceRole("EMR_DefaultRole")
                .withJobFlowRole("name-of-role-created")
                .withInstances(jobFlowInstanceConfig)
                .withSecurityConfiguration("Security configuration Name");
    
    RunJobFlowResult runJobFlowResult = emrClient.runJobFlow(request);
    

我收到以下错误:

com.amazonaws.services.elasticmapreduce.model.AmazonElasticMapReduceException: Role '' is not well-formed. (Service: AmazonElasticMapReduce; Status Code: 400; Error Code: ValidationException; Request ID: 0d5ed77e-ed0e-49fd-bd33-f88213ce08c3)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1701)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1356)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1102)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:759)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:733)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:715)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:675)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:657)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:521)
    at com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient.doInvoke(AmazonElasticMapReduceClient.java:2043)
    at com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient.invoke(AmazonElasticMapReduceClient.java:2010)
    at com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient.invoke(AmazonElasticMapReduceClient.java:1999)
    at com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient.executeRunJobFlow(AmazonElasticMapReduceClient.java:1770)
    at com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient.runJobFlow(AmazonElasticMapReduceClient.java:1742)

由于上述错误表示角色格式不正确,我尝试了不同的格式,但仍然遇到同样的问题。以下是我在 .withJobFlowRole("name-of-role-created") 中添加的不同格式

arn:aws:iam::639116131780:role/name-of-role-created
arn:aws:iam::639116131780:instance-profile/name-of-role-created
arn:aws:iam::639116131780:role/name-of-role-created/*
arn:aws:iam::639116131780:instance-profile/name-of-role-created/*
arn:aws:sts::639116131780:assumed-role/name-of-role-created
arn:aws:sts::639116131780:assumed-role/name-of-role-created/*

我每次都遇到同样的错误。

com.amazonaws.services.elasticmapreduce.model.AmazonElasticMapReduceException: Role 'arn:aws:iam::639116131780:role/name-of-role-created' is not well-formed. (Service: AmazonElasticMapReduce; Status Code: 400; Error Code: ValidationException; Request ID: 0d5ed77e-ed0e-49fd-bd33-f88213ce08c3)

【问题讨论】:

  • 你明白我的回答了吗?我可以解释更多。

标签: amazon-web-services amazon-ec2 amazon-emr aws-java-sdk


【解决方案1】:

根据docs,JobFlowRole参数不是ARN,而只是一个字符串,如EMR_EC2_DefaultRole(默认值)。使用这样的格式。

【讨论】:

    【解决方案2】:

    JobFlowRole 是应用于 EMR 实例的角色,它不是您创建 EMR 时使用的角色。我认为您误读了该选项。

    如果您想申请不使用 API 密钥的角色,那么您必须挖掘您的 AWS 凭证。例如在 S3 中,

    S3Client s3 = S3Client.builder()
                  .credentialsProvider(InstanceProfileCredentialsProvider.builder().build())
                  .build();
    

    在哪里

    InstanceProfileCredentialsProvider.builder().build()
    

    使用实例的角色。

    【讨论】:

    • 我解决了这个问题。是的,你是对的,这不是创建 EMR 的角色。但无论提供 InstanceProfileCredentialsProvider.builder().build() 我都能够创建集群。我使用了默认角色并且没有使用凭据。要求我们的 AWS 团队更改默认角色的权限。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 2018-07-13
    • 1970-01-01
    相关资源
    最近更新 更多