This topic describes how to call EMR API operations to create a semi-hosted Hadoop cluster.

Basic cluster information

Basic information about the cluster that is used in the examples of this topic:
  • Zone: Hangzhou Zone I
  • Billing method: pay-as-you-go
  • Cluster name: emr_openapi_demo
  • High availability enabled. Instance details:
    • Two master instances of the ecs.g5.xlarge type, one 120 GiB Enhanced SSD as the system disk, and one 80 GiB ultra disk as the data disk.
    • Two core instances of the ecs.g5.2xlarge type, one 120 GiB Enhanced SSD as the system disk, and four 80 GiB ultra disks as data disks.
    • Two task instances of the ecs.c5.2xlarge type, one 120 GiB Enhanced SSD as the system disk, and four 80 GiB ultra disks as data disks.
  • Public IP address assignment enabled
  • Logon password specified
  • Component configurations customized
    Component Configuration file Key Value
    Yarn yarn-site.xml yarn_nodemanager_heapsize 1234
    Hive hive-site.xml hive.metastore.warehouse.dir /user/hive/warehouse_emr

Examples:

  • 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

More configurations

For information about other configurations, see CreateClusterV2. You can click tiaoshi to enable OpenAPI Explorer to automatically generate code based on the entered configuration items.
Note
Two groups of parameters are used to specify billing methods and subscription periods:
  • ChargeType and Period: specify the billing method and subscription period when HostGroupType is Master or Core.
  • HostGroup.N.ChargeType and HostGroup.N.Period: specify the billing method and subscription period when HostGroupType is Task.
  • The following table describes the parameters of a subscription cluster.
    Parameter Description
    ChargeType The billing method. Valid values:
    • PostPaid: pay-as-you-go
    • PrePaid: subscription
    Period The subscription period. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, and 36. Unit: months. Specify this parameter when ChargeType is set to PrePaid.
    HostGroup.N.ChargeType The billing method of host group N.
    HostGroup.N.Period The subscription period. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, and 36. Unit: months. Specify this parameter when HostGroup.n.ChargeType is set to PrePaid.
  • The following table describes the parameters of a gateway cluster.
    When you create a gateway instance in a gateway cluster, you must set HostGroup.N.HostGroupType to GATEWAY to define the instance.
    Parameter Description
    ClusterType Set this parameter to GATEWAY.
    HostGroup.N.HostGroupType Set this parameter to GATEWAY.
    RelatedClusterId The ID of the EMR cluster that is associated with the gateway cluster.