How to create a EMR Cluster using Java AWS SDK

0 votes
Can someone help me with the java code to create a EMR cluster? I am using Java AWS SDK. Any help is appreciated.
Feb 27, 2019 in AWS by Reshmi Bhattacharya
1,590 views

1 answer to this question.

0 votes

The Java code for creating an AWS EMR Cluster is as follows:-

import java.io.IOException;
import com.amazonaws.auth.AWSCredentials;
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.HadoopJarStepConfig;
import com.amazonaws.services.elasticmapreduce.model.StepConfig;
import com.amazonaws.services.elasticmapreduce.util.StepFactory;

public class main {
    private static final AWSCredentials AWS_CREDENTIALS;
    
    static {
        // Your accesskey and secretkey
        AWS_CREDENTIALS = new BasicAWSCredentials(
                "Access Key",
                "Secret Key"
        );
    }

    public static void main(String[] args) {
        
        
        AmazonElasticMapReduce client = new AmazonElasticMapReduceClient(AWS_CREDENTIALS);
        StepConfig hive = new StepConfig("Hive", new StepFactory().newInstallHiveStep());

        HadoopJarStepConfig hadoopConfig1 = new HadoopJarStepConfig()
            .withJar("s3://mybucket/my-jar-location1");
        StepConfig customStep = new StepConfig("Step1", hadoopConfig1);

        AddJobFlowStepsResult result = client.addJobFlowSteps(new AddJobFlowStepsRequest()
          .withJobFlowId("j-id")
          .withSteps(hive, customStep));
        
          System.out.println(result.getStepIds());

    }
}

This will create a 2 node cluster, 1 master and 1 slave. Hope this helps.

answered Feb 27, 2019 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer

How to create a DynamoDB table using Java SDK?

The code to create a table in ...READ MORE

answered Feb 23, 2019 in AWS by Priyaj
• 58,020 points
2,566 views
0 votes
1 answer

How to create a redshift cluster using AWS CLI?

You can create your cluster using AWS ...READ MORE

answered Feb 25, 2019 in AWS by Priyaj
• 58,020 points
1,235 views
0 votes
1 answer

How to create EMR cluster using AWS CLI?

The command to create EMR cluster using ...READ MORE

answered Feb 27, 2019 in AWS by Priyaj
• 58,020 points
1,964 views
0 votes
1 answer
+1 vote
2 answers
+1 vote
1 answer
0 votes
1 answer

How to create a VPC using Java SDK?

You can create a VPC using the ...READ MORE

answered Feb 21, 2019 in AWS by Priyaj
• 58,020 points
2,754 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP