使用Java创建EMR集群

时间:2018-09-09 03:05:58

标签: java aws-lambda aws-sdk amazon-emr

我正在尝试使用Java创建EMR集群。我已经创建了jar文件,并将其放入lambda函数中。我正在从AWS Step函数调用lambda。我创建了包含AWS JAVA SDK依赖项的maven程序包,并且还导入了所有程序包

 import java.io.IOException;
 import com.amazonaws.auth.*;
 import com.amazonaws.auth.BasicAWSCredentials;
 import com.amazonaws.auth.PropertiesCredentials;
 import com.amazonaws.services.elasticmapreduce.*;
 import com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsRequest;
 import com.amazonaws.services.elasticmapreduce.model.AddJobFlowStepsResult;
 import com.amazonaws.services.elasticmapreduce.model.RunJobFlowRequest;
 import com.amazonaws.services.elasticmapreduce.model.*;
 import com.amazonaws.services.elasticmapreduce.model.HadoopJarStepConfig;
 import com.amazonaws.services.elasticmapreduce.model.StepConfig;
 import com.amazonaws.services.elasticmapreduce.util.StepFactory;
 import com.amazonaws.AmazonServiceException;
 import com.amazonaws.auth.AWSCredentials;
 import com.amazonaws.auth.BasicAWSCredentials;

公共类CreateCluster {

public static void main(String[] args) {
    AWSCredentials credentials = new BasicAWSCredentials("access key", "secret key");
    // myApp={[Hadoop]};
    AmazonElasticMapReduceClient emr = new AmazonElasticMapReduceClient(credentials);
    String COMMAND_RUNNER = "command-runner.jar";
    String DEBUGGING_COMMAND = "state-pusher-script";
    String DEBUGGING_NAME = "Setup Hadoop Debugging";

    StepFactory stepFactory = new StepFactory();

    StepConfig enabledebugging = new StepConfig()
            .withName(DEBUGGING_NAME)
            .withActionOnFailure(ActionOnFailure.TERMINATE_CLUSTER)
            .withHadoopJarStep(new HadoopJarStepConfig()
                    .withJar(COMMAND_RUNNER)
                    .withArgs(DEBUGGING_COMMAND));

    RunJobFlowRequest request = new RunJobFlowRequest()
            .withName("REMR")
            .withReleaseLabel("emr-5.16.0")
            .withSteps(enabledebugging)
            //  .withApplications(myApp)
            .withLogUri("s3n://r.base.ihm/emr-log/")
            .withServiceRole("service_role")
            .withJobFlowRole("jobflow_role")
            .withInstances(new JobFlowInstancesConfig()
                    .withEc2KeyName("emr")
                    .withEc2SubnetId("subnet-d1fbb8ee")
                    .withInstanceCount(3)
                    .withKeepJobFlowAliveWhenNoSteps(false)
                    .withMasterInstanceType("m4.large")
                    .withSlaveInstanceType("m4.large"));

    RunJobFlowResult result = emr.runJobFlow(request);

}

} 但仍然出现错误

  

java.lang.NoClassDefFoundError

     

{       “ errorMessage”:“加载类com.ihm.base.spark.CreateCluster:com / amazonaws / auth / AWSCredentials时出错”,       “ errorType”:“ java.lang.NoClassDefFoundError”      }

关于我在这里缺少什么的任何想法?

0 个答案:

没有答案