기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
는 Amazon EMR 기능이 포함된 세 가지 패키지를 AWS SDK for Java 제공합니다.
이 패키지에 대한 자세한 내용은 AWS SDK for Java API 참조를 참조하세요.
다음 예제에서는 SDK가 Amazon EMR로 프로그래밍을 간소화할 수 있는 방법을 보여줍니다. 아래 코드 샘플에서는 일반 Amazon EMR 단계 유형을 생성하기 위한 헬퍼 클래스인 StepFactory
객체를 사용하여 디버깅이 활성화된 상태에서 대화형 Hive 클러스터를 생성합니다.
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());
}
}
최소한 각각 EMR_DefaultRole 및 EMR_EC2_DefaultRole에 해당하는 서비스 역할 및 작업 흐름 역할을 전달해야 합니다. 동일한 계정에 대해이 AWS CLI 명령을 호출하여이 작업을 수행할 수 있습니다. 먼저 이러한 역할이 이미 존재하는지 알아봅니다.
aws iam list-roles | grep EMR
존재하는 경우 인스턴스 프로파일(EMR_EC2_DefaultRole) 및 서비스 역할(EMR_DefaultRole)이 모두 표시됩니다.
"RoleName": "EMR_DefaultRole", "Arn": "arn:aws:iam::
AccountID
:role/EMR_DefaultRole" "RoleName": "EMR_EC2_DefaultRole", "Arn": "arn:aws:iam::AccountID
:role/EMR_EC2_DefaultRole"
기본 역할이 존재하지 않는 경우 다음 명령을 사용하여 이러한 역할을 생성할 수 있습니다.
aws emr create-default-roles