本文介绍如何通过EMR OpenAPI创建一个Hadoop半托管集群。

集群基本信息

已获取集群如下信息:
  • 可用区: 华东1(杭州)可用区I。
  • 付费类型:按量付费。
  • 集群名称:emr_openapi_demo。
  • 开启高可用,详细实例:
    • 2个Master,每个Master ecs.g5.xlarge,系统盘为1*120G的ESSD,数据盘为1*80G的高效云盘。
    • 2个Core,每台Core ecs.g5.2xlarge,系统盘为1*120G的ESSD,数据盘为4*80G的高效云盘。
    • 2个Task,每台Task ecs.c5.2xlarge,系统盘为1*120G的ESSD,数据盘为4*80G的高效云盘。
  • 开启挂载公网。
  • 设置登录密码。
  • 自定义组件配置。
    组件名 配置文件 Key Value
    Yarn yarn-site.xml yarn_nodemanager_heapsize 1234
    Hive hive-site.xml hive.metastore.warehouse.dir /user/hive/warehouse_emr

EMR OpenAPI示例

  • Python
    #!/usr/bin/env python
    #coding=utf-8
    
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.acs_exception.exceptions import ClientException
    from aliyunsdkcore.acs_exception.exceptions import ServerException
    from aliyunsdkemr.request.v20160408.CreateClusterV2Request import CreateClusterV2Request
    
    client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
    
    request = CreateClusterV2Request()
    request.set_accept_format('json')
    
    request.set_Name("emr_openapi_demo")
    request.set_ZoneId("cn-hangzhou-i")
    request.set_EmrVer("EMR-3.23.0")
    request.set_ClusterType("HADOOP")
    request.set_HostGroups([
      {
        "HostGroupName": "master_group",
        "HostGroupType": "MASTER",
        "ChargeType": "PostPaid",
        "NodeCount": 2,
        "InstanceType": "ecs.g5.xlarge",
        "DiskType": "CLOUD_EFFICIENCY",
        "DiskCapacity": 80,
        "DiskCount": 1,
        "SysDiskType": "CLOUD_ESSD",
        "SysDiskCapacity": 120,
        "VSwitchId": "vsw-bp11t4amri1iuj*****"
      },
      {
        "HostGroupName": "core_group",
        "HostGroupType": "CORE",
        "ChargeType": "PostPaid",
        "NodeCount": 2,
        "InstanceType": "ecs.g5.2xlarge",
        "DiskType": "CLOUD_EFFICIENCY",
        "DiskCapacity": 80,
        "DiskCount": 4,
        "SysDiskType": "CLOUD_ESSD",
        "SysDiskCapacity": 120,
        "VSwitchId": "vsw-bp11t4amri1iuj*****"
      },
      {
        "HostGroupName": "task_group",
        "HostGroupType": "TASK",
        "ChargeType": "PostPaid",
        "NodeCount": 2,
        "InstanceType": "ecs.c5.xlarge",
        "DiskType": "CLOUD_EFFICIENCY",
        "DiskCapacity": 80,
        "DiskCount": 4,
        "SysDiskType": "CLOUD_ESSD",
        "SysDiskCapacity": 120,
        "VSwitchId": "vsw-bp11t4amri1iuj*****"
      }
    ])
    request.set_SecurityGroupId("sg-bp13cqwumhn7x*****")
    request.set_IsOpenPublicIp(True)
    request.set_SecurityGroupName("newgroup")
    request.set_ChargeType("PostPaid")
    request.set_VpcId("vpc-bp1gjl3y9fezuk*****")
    request.set_VSwitchId("vsw-bp11t4amri1iuj*****")
    request.set_NetType("vpc")
    request.set_UserDefinedEmrEcsRole("AliyunEmrEcsDefaultRole")
    request.set_HighAvailabilityEnable(True)
    request.set_IoOptimized(True)
    request.set_SshEnable(True)
    request.set_MasterPwd("EMRtest12345!")
    request.set_DepositType("HALF_MANAGED")
    request.set_MachineType("ECS")
    request.set_Configs([
      {
        "ServiceName": "YARN",
        "FileName": "yarn-site",
        "ConfigKey": "yarn_nodemanager_heapsize",
        "ConfigValue": "1234"
      },
      {
        "ServiceName": "HIVE",
        "FileName": "hive-site",
        "ConfigKey": "hive.metastore.warehouse.dir",
        "ConfigValue": "/user/hive/warehouse_emr"
      }
    ])
    
    response = client.do_action_with_exception(request)
    # python2:  print(response) 
    print(str(response, encoding='utf-8'))
  • Java
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.emr.model.v20160408.*;
    
    public class CreateClusterV2 {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            CreateClusterV2Request request = new CreateClusterV2Request();
            request.setRegionId("cn-hangzhou");
            request.setName("emr_openapi_demo");
            request.setZoneId("cn-hangzhou-i");
            request.setEmrVer("EMR-3.23.0");
            request.setClusterType("HADOOP");
    
            List<CreateClusterV2Request.HostGroup> hostGroupList = new ArrayList<CreateClusterV2Request.HostGroup>();
    
            CreateClusterV2Request.HostGroup hostGroup1 = new CreateClusterV2Request.HostGroup();
            hostGroup1.setHostGroupName("master_group");
            hostGroup1.setHostGroupType("MASTER");
            hostGroup1.setChargeType("PostPaid");
            hostGroup1.setNodeCount(2);
            hostGroup1.setInstanceType("ecs.g5.xlarge");
            hostGroup1.setDiskType("CLOUD_EFFICIENCY");
            hostGroup1.setDiskCapacity(80);
            hostGroup1.setDiskCount(1);
            hostGroup1.setSysDiskType("CLOUD_ESSD");
            hostGroup1.setSysDiskCapacity(120);
            hostGroup1.setVSwitchId("vsw-bp11t4amri1iuj*****");
            hostGroupList.add(hostGroup1);
    
            CreateClusterV2Request.HostGroup hostGroup2 = new CreateClusterV2Request.HostGroup();
            hostGroup2.setHostGroupName("core_group");
            hostGroup2.setHostGroupType("CORE");
            hostGroup2.setChargeType("PostPaid");
            hostGroup2.setNodeCount(2);
            hostGroup2.setInstanceType("ecs.g5.2xlarge");
            hostGroup2.setDiskType("CLOUD_EFFICIENCY");
            hostGroup2.setDiskCapacity(80);
            hostGroup2.setDiskCount(4);
            hostGroup2.setSysDiskType("CLOUD_ESSD");
            hostGroup2.setSysDiskCapacity(120);
            hostGroup2.setVSwitchId("vsw-bp11t4amri1iuj*****");
            hostGroupList.add(hostGroup2);
    
            CreateClusterV2Request.HostGroup hostGroup3 = new CreateClusterV2Request.HostGroup();
            hostGroup3.setHostGroupName("task_group");
            hostGroup3.setHostGroupType("TASK");
            hostGroup3.setChargeType("PostPaid");
            hostGroup3.setNodeCount(2);
            hostGroup3.setInstanceType("ecs.c5.xlarge");
            hostGroup3.setDiskType("CLOUD_EFFICIENCY");
            hostGroup3.setDiskCapacity(80);
            hostGroup3.setDiskCount(4);
            hostGroup3.setSysDiskType("CLOUD_ESSD");
            hostGroup3.setSysDiskCapacity(120);
            hostGroup3.setVSwitchId("vsw-bp11t4amri1iuj*****");
            hostGroupList.add(hostGroup3);
            request.setHostGroups(hostGroupList);
            request.setSecurityGroupId("sg-bp13cqwumhn7x*****");
            request.setIsOpenPublicIp(true);
            request.setSecurityGroupName("newgroup");
            request.setChargeType("PostPaid");
            request.setVpcId("vpc-bp1gjl3y9fezukq*****");
            request.setVSwitchId("vsw-bp11t4amri1iuj*****");
            request.setNetType("vpc");
            request.setUserDefinedEmrEcsRole("AliyunEmrEcsDefaultRole");
            request.setHighAvailabilityEnable(true);
            request.setIoOptimized(true);
            request.setSshEnable(true);
            request.setMasterPwd("EMRtest12345!");
            request.setDepositType("HALF_MANAGED");
            request.setMachineType("ECS");
    
            List<CreateClusterV2Request.Config> configList = new ArrayList<CreateClusterV2Request.Config>();
    
            CreateClusterV2Request.Config config1 = new CreateClusterV2Request.Config();
            config1.setServiceName("YARN");
            config1.setFileName("yarn-site");
            config1.setConfigKey("yarn_nodemanager_heapsize");
            config1.setConfigValue("1234");
            configList.add(config1);
    
            CreateClusterV2Request.Config config2 = new CreateClusterV2Request.Config();
            config2.setServiceName("HIVE");
            config2.setFileName("hive-site");
            config2.setConfigKey("hive.metastore.warehouse.dir");
            config2.setConfigValue("/user/hive/warehouse_emr");
            configList.add(config2);
            request.setConfigs(configList);
    
            try {
                CreateClusterV2Response response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }
  • Node.js
    const Core = require('@alicloud/pop-core');
    
    var client = new Core({
      accessKeyId: '<accessKeyId>',
      accessKeySecret: '<accessSecret>',
      endpoint: 'https://emr.aliyuncs.com',
      apiVersion: '2016-04-08'
    });
    
    var params = {
      "RegionId": "cn-hangzhou",
      "Name": "emr_openapi_demo",
      "ZoneId": "cn-hangzhou-i",
      "EmrVer": "EMR-3.23.0",
      "ClusterType": "HADOOP",
      "HostGroup.1.HostGroupName": "master_group",
      "HostGroup.1.HostGroupType": "MASTER",
      "HostGroup.1.ChargeType": "PostPaid",
      "HostGroup.1.NodeCount": 2,
      "HostGroup.1.InstanceType": "ecs.g5.xlarge",
      "HostGroup.1.DiskType": "CLOUD_EFFICIENCY",
      "HostGroup.1.DiskCapacity": 80,
      "HostGroup.1.DiskCount": 1,
      "HostGroup.1.SysDiskType": "CLOUD_ESSD",
      "HostGroup.1.SysDiskCapacity": 120,
      "HostGroup.1.VSwitchId": "vsw-bp11t4amri1iuj*****",
      "HostGroup.2.HostGroupName": "core_group",
      "HostGroup.2.HostGroupType": "CORE",
      "HostGroup.2.ChargeType": "PostPaid",
      "HostGroup.2.NodeCount": 2,
      "HostGroup.2.InstanceType": "ecs.g5.2xlarge",
      "HostGroup.2.DiskType": "CLOUD_EFFICIENCY",
      "HostGroup.2.DiskCapacity": 80,
      "HostGroup.2.DiskCount": 4,
      "HostGroup.2.SysDiskType": "CLOUD_ESSD",
      "HostGroup.2.SysDiskCapacity": 120,
      "HostGroup.2.VSwitchId": "vsw-bp11t4amri1iuj*****",
      "HostGroup.3.HostGroupName": "task_group",
      "HostGroup.3.HostGroupType": "TASK",
      "HostGroup.3.ChargeType": "PostPaid",
      "HostGroup.3.NodeCount": 2,
      "HostGroup.3.InstanceType": "ecs.c5.xlarge",
      "HostGroup.3.DiskType": "CLOUD_EFFICIENCY",
      "HostGroup.3.DiskCapacity": 80,
      "HostGroup.3.DiskCount": 4,
      "HostGroup.3.SysDiskType": "CLOUD_ESSD",
      "HostGroup.3.SysDiskCapacity": 120,
      "HostGroup.3.VSwitchId": "vsw-bp11t4amri1iuj*****",
      "SecurityGroupId": "sg-bp13cqwumhn7xm*****",
      "IsOpenPublicIp": true,
      "SecurityGroupName": "newgroup",
      "ChargeType": "PostPaid",
      "VpcId": "vpc-bp1gjl3y9fezukq*****",
      "VSwitchId": "vsw-bp11t4amri1iuj*****",
      "NetType": "vpc",
      "UserDefinedEmrEcsRole": "AliyunEmrEcsDefaultRole",
      "HighAvailabilityEnable": true,
      "IoOptimized": true,
      "SshEnable": true,
      "MasterPwd": "EMRtest12345!",
      "DepositType": "HALF_MANAGED",
      "MachineType": "ECS",
      "Config.1.ServiceName": "YARN",
      "Config.1.FileName": "yarn-site",
      "Config.1.ConfigKey": "yarn_nodemanager_heapsize",
      "Config.1.ConfigValue": "1234",
      "Config.2.ServiceName": "HIVE",
      "Config.2.FileName": "hive-site",
      "Config.2.ConfigKey": "hive.metastore.warehouse.dir",
      "Config.2.ConfigValue": "/user/hive/warehouse_emr"
    }
    
    var requestOption = {
      method: 'POST'
    };
    
    client.request('CreateClusterV2', params, requestOption).then((result) => {
      console.log(JSON.stringify(result));
    }, (ex) => {
      console.log(ex);
    })
  • Go
    package main
    
    import (
        "fmt"
          "github.com/aliyun/alibaba-cloud-sdk-go/services/emr"
    
        "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
    
    )
    
    func main() {
        client, err := emr.NewClientWithAccessKey("cn-hangzhou", "<accessKeyId>", "<accessSecret>")
    
        request := emr.CreateCreateClusterV2Request()
        request.Scheme = "https"
    
      request.Name = "emr_openapi_demo"
      request.ZoneId = "cn-hangzhou-i"
      request.EmrVer = "EMR-3.23.0"
      request.ClusterType = "HADOOP"
      request.HostGroup = &[]emr.CreateClusterV2HostGroup{
        {
          HostGroupName: "master_group",
          HostGroupType: "MASTER",
          ChargeType: "PostPaid",
          NodeCount: "2",
          InstanceType: "ecs.g5.xlarge",
          DiskType: "CLOUD_EFFICIENCY",
          DiskCapacity: "80",
          DiskCount: "1",
          SysDiskType: "CLOUD_ESSD",
          SysDiskCapacity: "120",
          VSwitchId: "vsw-bp11t4amri1iuj*****",
        },
        {
          HostGroupName: "core_group",
          HostGroupType: "CORE",
          ChargeType: "PostPaid",
          NodeCount: "2",
          InstanceType: "ecs.g5.2xlarge",
          DiskType: "CLOUD_EFFICIENCY",
          DiskCapacity: "80",
          DiskCount: "4",
          SysDiskType: "CLOUD_ESSD",
          SysDiskCapacity: "120",
          VSwitchId: "vsw-bp11t4amri1iuj*****",
        },
        {
          HostGroupName: "task_group",
          HostGroupType: "TASK",
          ChargeType: "PostPaid",
          NodeCount: "2",
          InstanceType: "ecs.c5.xlarge",
          DiskType: "CLOUD_EFFICIENCY",
          DiskCapacity: "80",
          DiskCount: "4",
          SysDiskType: "CLOUD_ESSD",
          SysDiskCapacity: "120",
          VSwitchId: "vsw-bp11t4amri1iuj*****",
        },
      }
      request.SecurityGroupId = "sg-bp13cqwumhn7x*****"
      request.IsOpenPublicIp = requests.NewBoolean(true)
      request.SecurityGroupName = "newgroup"
      request.ChargeType = "PostPaid"
      request.VpcId = "vpc-bp1gjl3y9fezukqf*****"
      request.VSwitchId = "vsw-bp11t4amri1iuj*****"
      request.NetType = "vpc"
      request.UserDefinedEmrEcsRole = "AliyunEmrEcsDefaultRole"
      request.HighAvailabilityEnable = requests.NewBoolean(true)
      request.IoOptimized = requests.NewBoolean(true)
      request.SshEnable = requests.NewBoolean(true)
      request.MasterPwd = "EMRtest12345!"
      request.DepositType = "HALF_MANAGED"
      request.MachineType = "ECS"
      request.Config = &[]emr.CreateClusterV2Config{
        {
          ServiceName: "YARN",
          FileName: "yarn-site",
          ConfigKey: "yarn_nodemanager_heapsize",
          ConfigValue: "1234",
        },
        {
          ServiceName: "HIVE",
          FileName: "hive-site",
          ConfigKey: "hive.metastore.warehouse.dir",
          ConfigValue: "/user/hive/warehouse_emr",
        },
      }
    
        response, err := client.CreateClusterV2(request)
        if err != nil {
            fmt.Print(err.Error())
        }
        fmt.Printf("response is %#v\n", response)
    }
  • PHP
    <?php
    use AlibabaCloud\Client\AlibabaCloud;
    use AlibabaCloud\Client\Exception\ClientException;
    use AlibabaCloud\Client\Exception\ServerException;
    
    // Download:https://github.com/aliyun/openapi-sdk-php
    // Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
    
    AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
                            ->regionId('cn-hangzhou')
                            ->asDefaultClient();
    
    try {
        $result = AlibabaCloud::rpc()
                              ->product('Emr')
                              // ->scheme('https') // https | http
                              ->version('2016-04-08')
                              ->action('CreateClusterV2')
                              ->method('POST')
                              ->host('emr.aliyuncs.com')
                              ->options([
                                            'query' => [
                                              'RegionId' => "cn-hangzhou",
                                              'Name' => "emr_openapi_demo",
                                              'ZoneId' => "cn-hangzhou-i",
                                              'EmrVer' => "EMR-3.23.0",
                                              'ClusterType' => "HADOOP",
                                              'HostGroup.1.HostGroupName' => "master_group",
                                              'HostGroup.1.HostGroupType' => "MASTER",
                                              'HostGroup.1.ChargeType' => "PostPaid",
                                              'HostGroup.1.NodeCount' => "2",
                                              'HostGroup.1.InstanceType' => "ecs.g5.xlarge",
                                              'HostGroup.1.DiskType' => "CLOUD_EFFICIENCY",
                                              'HostGroup.1.DiskCapacity' => "80",
                                              'HostGroup.1.DiskCount' => "1",
                                              'HostGroup.1.SysDiskType' => "CLOUD_ESSD",
                                              'HostGroup.1.SysDiskCapacity' => "120",
                                              'HostGroup.1.VSwitchId' => "vsw-bp11t4amri1iuj*****",
                                              'HostGroup.2.HostGroupName' => "core_group",
                                              'HostGroup.2.HostGroupType' => "CORE",
                                              'HostGroup.2.ChargeType' => "PostPaid",
                                              'HostGroup.2.NodeCount' => "2",
                                              'HostGroup.2.InstanceType' => "ecs.g5.2xlarge",
                                              'HostGroup.2.DiskType' => "CLOUD_EFFICIENCY",
                                              'HostGroup.2.DiskCapacity' => "80",
                                              'HostGroup.2.DiskCount' => "4",
                                              'HostGroup.2.SysDiskType' => "CLOUD_ESSD",
                                              'HostGroup.2.SysDiskCapacity' => "120",
                                              'HostGroup.2.VSwitchId' => "vsw-bp11t4amri1iuj*****",
                                              'HostGroup.3.HostGroupName' => "task_group",
                                              'HostGroup.3.HostGroupType' => "TASK",
                                              'HostGroup.3.ChargeType' => "PostPaid",
                                              'HostGroup.3.NodeCount' => "2",
                                              'HostGroup.3.InstanceType' => "ecs.c5.xlarge",
                                              'HostGroup.3.DiskType' => "CLOUD_EFFICIENCY",
                                              'HostGroup.3.DiskCapacity' => "80",
                                              'HostGroup.3.DiskCount' => "4",
                                              'HostGroup.3.SysDiskType' => "CLOUD_ESSD",
                                              'HostGroup.3.SysDiskCapacity' => "120",
                                              'HostGroup.3.VSwitchId' => "vsw-bp11t4amri1iuj*****",
                                              'SecurityGroupId' => "sg-bp13cqwumhn7x*****",
                                              'IsOpenPublicIp' => "true",
                                              'SecurityGroupName' => "newgroup",
                                              'ChargeType' => "PostPaid",
                                              'VpcId' => "vpc-bp1gjl3y9fezukqf*****",
                                              'VSwitchId' => "vsw-bp11t4amri1iuj*****",
                                              'NetType' => "vpc",
                                              'UserDefinedEmrEcsRole' => "AliyunEmrEcsDefaultRole",
                                              'HighAvailabilityEnable' => "true",
                                              'IoOptimized' => "true",
                                              'SshEnable' => "true",
                                              'MasterPwd' => "EMRtest12345!",
                                              'DepositType' => "HALF_MANAGED",
                                              'MachineType' => "ECS",
                                              'Config.1.ServiceName' => "YARN",
                                              'Config.1.FileName' => "yarn-site",
                                              'Config.1.ConfigKey' => "yarn_nodemanager_heapsize",
                                              'Config.1.ConfigValue' => "1234",
                                              'Config.2.ServiceName' => "HIVE",
                                              'Config.2.FileName' => "hive-site",
                                              'Config.2.ConfigKey' => "hive.metastore.warehouse.dir",
                                              'Config.2.ConfigValue' => "/user/hive/warehouse_emr",
                                            ],
                                        ])
                              ->request();
        print_r($result->toArray());
    } catch (ClientException $e) {
        echo $e->getErrorMessage() . PHP_EOL;
    } catch (ServerException $e) {
        echo $e->getErrorMessage() . PHP_EOL;
    }
  • .Net
    using System;
    using System.Collections.Generic;
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Exceptions;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Emr.Model.V20160408;
    
    namespace EmrDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
                DefaultAcsClient client = new DefaultAcsClient(profile);
    
                var request = new CreateClusterV2Request();
                request.Name = "emr_openapi_demo";
                request.ZoneId = "cn-hangzhou-i";
                request.EmrVer = "EMR-3.23.0";
                request.ClusterType = "HADOOP";
    
                var hostGroupList = new List<CreateClusterV2Request.HostGroup>();
    
                var hostGroup1 = new CreateClusterV2Request.HostGroup();
                hostGroup1.HostGroupName = "master_group";
                hostGroup1.HostGroupType = "MASTER";
                hostGroup1.ChargeType = "PostPaid";
                hostGroup1.NodeCount = 2;
                hostGroup1.InstanceType = "ecs.g5.xlarge";
                hostGroup1.DiskType = "CLOUD_EFFICIENCY";
                hostGroup1.DiskCapacity = 80;
                hostGroup1.DiskCount = 1;
                hostGroup1.SysDiskType = "CLOUD_ESSD";
                hostGroup1.SysDiskCapacity = 120;
                hostGroup1.VSwitchId = "vsw-bp11t4amri1iuj*****";
                hostGroupList.Add(hostGroup1);
    
                var hostGroup2 = new CreateClusterV2Request.HostGroup();
                hostGroup2.HostGroupName = "core_group";
                hostGroup2.HostGroupType = "CORE";
                hostGroup2.ChargeType = "PostPaid";
                hostGroup2.NodeCount = 2;
                hostGroup2.InstanceType = "ecs.g5.2xlarge";
                hostGroup2.DiskType = "CLOUD_EFFICIENCY";
                hostGroup2.DiskCapacity = 80;
                hostGroup2.DiskCount = 4;
                hostGroup2.SysDiskType = "CLOUD_ESSD";
                hostGroup2.SysDiskCapacity = 120;
                hostGroup2.VSwitchId = "vsw-bp11t4amri1iuj*****";
                hostGroupList.Add(hostGroup2);
    
                var hostGroup3 = new CreateClusterV2Request.HostGroup();
                hostGroup3.HostGroupName = "task_group";
                hostGroup3.HostGroupType = "TASK";
                hostGroup3.ChargeType = "PostPaid";
                hostGroup3.NodeCount = 2;
                hostGroup3.InstanceType = "ecs.c5.xlarge";
                hostGroup3.DiskType = "CLOUD_EFFICIENCY";
                hostGroup3.DiskCapacity = 80;
                hostGroup3.DiskCount = 4;
                hostGroup3.SysDiskType = "CLOUD_ESSD";
                hostGroup3.SysDiskCapacity = 120;
                hostGroup3.VSwitchId = "vsw-bp11t4amri1iuj*****";
                hostGroupList.Add(hostGroup3);
                request.HostGroups = hostGroupList;
                request.SecurityGroupId = "sg-bp13cqwumhn7x*****";
                request.IsOpenPublicIp = true;
                request.SecurityGroupName = "newgroup";
                request.ChargeType = "PostPaid";
                request.VpcId = "vpc-bp1gjl3y9fezukq*****";
                request.VSwitchId = "vsw-bp11t4amri1iuj*****";
                request.NetType = "vpc";
                request.UserDefinedEmrEcsRole = "AliyunEmrEcsDefaultRole";
                request.HighAvailabilityEnable = true;
                request.IoOptimized = true;
                request.SshEnable = true;
                request.MasterPwd = "EMRtest12345!";
                request.DepositType = "HALF_MANAGED";
                request.MachineType = "ECS";
    
                var configList = new List<CreateClusterV2Request.Config>();
    
                var config1 = new CreateClusterV2Request.Config();
                config1.ServiceName = "YARN";
                config1.FileName = "yarn-site";
                config1.ConfigKey = "yarn_nodemanager_heapsize";
                config1.ConfigValue = "1234";
                configList.Add(config1);
    
                var config2 = new CreateClusterV2Request.Config();
                config2.ServiceName = "HIVE";
                config2.FileName = "hive-site";
                config2.ConfigKey = "hive.metastore.warehouse.dir";
                config2.ConfigValue = "/user/hive/warehouse_emr";
                configList.Add(config2);
                request.Configs = configList;
                try {
                    var response = client.GetAcsResponse(request);
                    Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
                }
                catch (ServerException e)
                {
                    Console.WriteLine(e);
                }
                catch (ClientException e)
                {
                    Console.WriteLine(e);
                }
            }
        }
    }
  • Ruby
    # gem install aliyunsdkcore
    
    require 'aliyunsdkcore'
    
    client = RPCClient.new(
      access_key_id:     '<accessKeyId>',
      access_key_secret: '<accessSecret>',
      endpoint: 'https://emr.aliyuncs.com',
      api_version: '2016-04-08'
    )
    
    response = client.request(
      action: 'CreateClusterV2',
      params: {
        "RegionId": "cn-hangzhou",
        "Name": "emr_openapi_demo",
        "ZoneId": "cn-hangzhou-i",
        "EmrVer": "EMR-3.23.0",
        "ClusterType": "HADOOP",
        "HostGroup.1.HostGroupName": "master_group",
        "HostGroup.1.HostGroupType": "MASTER",
        "HostGroup.1.ChargeType": "PostPaid",
        "HostGroup.1.NodeCount": 2,
        "HostGroup.1.InstanceType": "ecs.g5.xlarge",
        "HostGroup.1.DiskType": "CLOUD_EFFICIENCY",
        "HostGroup.1.DiskCapacity": 80,
        "HostGroup.1.DiskCount": 1,
        "HostGroup.1.SysDiskType": "CLOUD_ESSD",
        "HostGroup.1.SysDiskCapacity": 120,
        "HostGroup.1.VSwitchId": "vsw-bp11t4amri1iuj*****",
        "HostGroup.2.HostGroupName": "core_group",
        "HostGroup.2.HostGroupType": "CORE",
        "HostGroup.2.ChargeType": "PostPaid",
        "HostGroup.2.NodeCount": 2,
        "HostGroup.2.InstanceType": "ecs.g5.2xlarge",
        "HostGroup.2.DiskType": "CLOUD_EFFICIENCY",
        "HostGroup.2.DiskCapacity": 80,
        "HostGroup.2.DiskCount": 4,
        "HostGroup.2.SysDiskType": "CLOUD_ESSD",
        "HostGroup.2.SysDiskCapacity": 120,
        "HostGroup.2.VSwitchId": "vsw-bp11t4amri1iuj*****",
        "HostGroup.3.HostGroupName": "task_group",
        "HostGroup.3.HostGroupType": "TASK",
        "HostGroup.3.ChargeType": "PostPaid",
        "HostGroup.3.NodeCount": 2,
        "HostGroup.3.InstanceType": "ecs.c5.xlarge",
        "HostGroup.3.DiskType": "CLOUD_EFFICIENCY",
        "HostGroup.3.DiskCapacity": 80,
        "HostGroup.3.DiskCount": 4,
        "HostGroup.3.SysDiskType": "CLOUD_ESSD",
        "HostGroup.3.SysDiskCapacity": 120,
        "HostGroup.3.VSwitchId": "vsw-bp11t4amri1iuj*****",
        "SecurityGroupId": "sg-bp13cqwumhn7x*****",
        "IsOpenPublicIp": true,
        "SecurityGroupName": "newgroup",
        "ChargeType": "PostPaid",
        "VpcId": "vpc-bp1gjl3y9fezuk*****",
        "VSwitchId": "vsw-bp11t4amri1iuj*****",
        "NetType": "vpc",
        "UserDefinedEmrEcsRole": "AliyunEmrEcsDefaultRole",
        "HighAvailabilityEnable": true,
        "IoOptimized": true,
        "SshEnable": true,
        "MasterPwd": "EMRtest12345!",
        "DepositType": "HALF_MANAGED",
        "MachineType": "ECS",
        "Config.1.ServiceName": "YARN",
        "Config.1.FileName": "yarn-site",
        "Config.1.ConfigKey": "yarn_nodemanager_heapsize",
        "Config.1.ConfigValue": "1234",
        "Config.2.ServiceName": "HIVE",
        "Config.2.FileName": "hive-site",
        "Config.2.ConfigKey": "hive.metastore.warehouse.dir",
        "Config.2.ConfigValue": "/user/hive/warehouse_emr"
    },
      opts: {
        method: 'POST'
      }
    )
    
    print response

更多配置

如果所需集群有其它的配置项,请参见CreateClusterV2,单击tiaoshi,可根据输入的配置项自动生成对应的代码。
说明
配置里有两组信息是和付费类型相关的:
  • 当机器组类型为Master和Core时,付费类型以ChargeType或Period为准。
  • 当机器组类型为Task时,付费类型以HostGroup.N.ChargeType或HostGroup.N.Period为准。
  • 创建包年包月集群参数描述如下。
    参数 描述
    ChargeType 付费类型:
    • PostPaid:按量付费。
    • PrePaid:包年包月。
    Period 包年包月时间(包月数有:1、2、3、4、5、6、7、8、9、12、24、36)。当ChargeTypePrePaid时,必填。
    HostGroup.N.ChargeType 机器组机器付费类型。
    HostGroup.N.Period 包年包月时间(包月数有1、2、3、4、5、6、7、8、9、12、24、36)。当HostGroup.n.ChargeTypePrePaid时,必填。
  • 创建Gateway集群参数描述如下。
    Gateway实例在Gateway集群中创建,需添加HostGroup.N.HostGroupType=GATEWAY的实例定义。
    参数 描述
    ClusterType 当创建Gateway集群时,取值为GATEWAY
    HostGroup.N.HostGroupType Gateway实例,取值为GATEWAY
    RelatedClusterId 当前是Gateway集群时,其关联的主集群ID。