Spark を使用したクラスターの作成 - Amazon EMR

Spark を使用したクラスターの作成

次の手順では、EMR コンソールで [Quick Options] (クイックオプション) を使用して、Spark がインストールされたクラスターを作成します。

[Advanced Options] (詳細オプション) を使用してクラスター設定を詳細にカスタマイズしたり、アプリケーションをプログラムでインストールするステップを送信してカスタムアプリケーションを実行したりすることもできます。どちらのクラスター作成オプションでも、Spark SQL メタストアとして AWS Glue を使用するように選択できます。詳細については、「Spark SQL のメタストアとしての AWS Glue Data Catalog の使用」を参照してください。

Spark がインストールされたクラスターを起動するには
  1. Amazon EMR コンソール (https://console.aws.amazon.com/emr) を開きます。

  2. [Create cluster] (クラスターの作成) を選択して、[Quick Options] (クイックオプション) を使用します。

  3. [Cluster name] (クラスター名) を入力します。

  4. [Software Configuration] (ソフトウェア設定) では、[Release] (リリース) オプションを選択します。

  5. [Applications] (アプリケーション) では、Spark アプリケーションバンドルを選択します。

  6. 必要に応じて他のオプションを選択し、[Create cluster (クラスターの作成)] を選択します。

    注記

    クラスターを作成する場合に Spark を設定するには、「Spark の設定」を参照してください。

AWS CLI を使用し、Spark がインストールされたクラスターを起動するには
  • 次のコマンドを使用してクラスターを作成します。

    aws emr create-cluster --name "Spark cluster" --release-label emr-5.36.1 --applications Name=Spark \ --ec2-attributes KeyName=myKey --instance-type m5.xlarge --instance-count 3 --use-default-roles
注記

読みやすくするために、Linux 行連続文字 (\) が含まれています。Linux コマンドでは、これらは削除することも、使用することもできます。Windows の場合、削除するか、キャレット (^) に置き換えてください。

SDK for Java を使用し、Spark がインストールされたクラスターを起動するには

SupportedProductConfig で使用される RunJobFlowRequest を使用して Spark をアプリケーションとして指定します。

  • 次の例は、Java を使用した Spark のあるクラスターを作成する方法を示します。

    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) { AWSCredentials credentials_profile = null; try { credentials_profile = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load credentials from .aws/credentials file. " + "Make sure that the credentials file exists and the profile name is specified within it.", e); } AmazonElasticMapReduce emr = AmazonElasticMapReduceClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(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()); Application spark = new Application().withName("Spark"); RunJobFlowRequest request = new RunJobFlowRequest() .withName("Spark Cluster") .withReleaseLabel("emr-5.20.0") .withSteps(enabledebugging) .withApplications(spark) .withLogUri("s3://path/to/my/logs/") .withServiceRole("EMR_DefaultRole") .withJobFlowRole("EMR_EC2_DefaultRole") .withInstances(new JobFlowInstancesConfig() .withEc2SubnetId("subnet-12ab3c45") .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()); } }