-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathcreate_cluster.java
More file actions
executable file
·73 lines (63 loc) · 3.25 KB
/
Copy pathcreate_cluster.java
File metadata and controls
executable file
·73 lines (63 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[emr.java.create-cluster.runjobflow]
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduce;
import com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClientBuilder;
import com.amazonaws.services.elasticmapreduce.model.*;
import com.amazonaws.services.elasticmapreduce.util.StepFactory;
public class Main {
public static void main(String[] args) {
AWSCredentialsProvider profile = null;
try {
credentials_profile = new ProfileCredentialsProvider("default"); // specifies any named profile in
// .aws/credentials as the credentials provider
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load credentials from .aws/credentials file. " +
"Make sure that the credentials file exists and that the profile name is defined within it.",
e);
}
// create an EMR client using the credentials and region specified in order to
// create the cluster
AmazonElasticMapReduce emr = AmazonElasticMapReduceClientBuilder.standard()
.withCredentials(credentials_profile)
.withRegion(Regions.US_WEST_1)
.build();
// create a step to enable debugging in the AWS Management Console
StepFactory stepFactory = new StepFactory();
StepConfig enabledebugging = new StepConfig()
.withName("Enable debugging")
.withActionOnFailure("TERMINATE_JOB_FLOW")
.withHadoopJarStep(stepFactory.newEnableDebuggingStep());
// specify applications to be installed and configured when EMR creates the
// cluster
Application hive = new Application().withName("Hive");
Application spark = new Application().withName("Spark");
Application ganglia = new Application().withName("Ganglia");
Application zeppelin = new Application().withName("Zeppelin");
// create the cluster
RunJobFlowRequest request = new RunJobFlowRequest()
.withName("MyClusterCreatedFromJava")
.withReleaseLabel("emr-5.20.0") // specifies the EMR release version label, we recommend the latest release
.withSteps(enabledebugging)
.withApplications(hive, spark, ganglia, zeppelin)
.withLogUri("s3://path/to/my/emr/logs") // a URI in S3 for log files is required when debugging is enabled
.withServiceRole("EMR_DefaultRole") // replace the default with a custom IAM service role if one is used
.withJobFlowRole("EMR_EC2_DefaultRole") // replace the default with a custom EMR role for the EC2 instance
// profile if one is used
.withInstances(new JobFlowInstancesConfig()
.withEc2SubnetId("subnet-12ab34c56")
.withEc2KeyName("myEc2Key")
.withInstanceCount(3)
.withKeepJobFlowAliveWhenNoSteps(true)
.withMasterInstanceType("m4.large")
.withSlaveInstanceType("m4.large"));
RunJobFlowResult result = emr.runJobFlow(request);
System.out.println("The cluster ID is " + result.toString());
}
}
// snippet-end:[emr.java.create-cluster.runjobflow]