Todos os produtos
Search
Central de documentação

Resource Orchestration Service:ALIYUN::EMR::SparkWorkspace

Última atualização: Oct 10, 2026

O tipo ALIYUN::EMR::SparkWorkspace cria um workspace do E-MapReduce Serverless Spark.

Sintaxe

{
  "Type": "ALIYUN::EMR::SparkWorkspace",
  "Properties": {
    "OssBucket": String,
    "PaymentType": String,
    "ResourceSpec": Map,
    "RamRoleName": String,
    "WorkspaceName": String,
    "AutoRenewPeriod": String,
    "AutoRenew": Boolean,
    "AutoStartSessionCluster": Boolean,
    "AutoRenewPeriodUnit": String,
    "DlfType": String,
    "Duration": String,
    "DlfCatalogId": String,
    "GpuSubscription": Map,
    "GpuSpec": List,
    "IpWhiteList": List,
    "PaymentDurationUnit": String,
    "ReleaseType": String,
    "ResourceGroupId": String,
    "Subscription": Map,
    "Tags": List
  }
}

Propriedades

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

OssBucket

String

Sim

Não

Caminho do bucket OSS do workspace.

O caminho deve seguir o formato oss://bucket-name/path/.

PaymentType

String

Sim

Não

Método de faturamento do workspace.

Valores válidos:

  • PostPaid: pagamento conforme o uso

  • PrePaid: assinatura

RamRoleName

String

Sim

Não

Função RAM para execução de jobs Spark.

Nenhuma

ResourceSpec

Map

Sim

Sim

Especificações de recursos do workspace.

Para mais informações, consulte ResourceSpec properties.

WorkspaceName

String

Sim

Sim

Nome do workspace.

O nome deve ter de 1 a 64 caracteres e pode conter caracteres chineses, letras, dígitos, hifens (-) e sublinhados (_).

AutoRenew

Boolean

Não

Não

Define se a renovação automática da assinatura está ativada.

Nenhuma

AutoRenewPeriod

String

Não

Não

Período de renovação automática.

Nenhuma

AutoRenewPeriodUnit

String

Não

Não

Unidade do período de renovação automática.

Valores válidos:

  • MONTH

AutoStartSessionCluster

Boolean

Não

Não

Indica se o cluster de sessão inicia automaticamente.

Nenhuma

DlfCatalogId

String

Não

Não

ID do catálogo DLF.

Nenhuma

DlfType

String

Não

Não

Tipo de DLF vinculado ao workspace.

Nenhuma

Duration

String

Não

Não

Duração da assinatura.

Intervalo válido: 1 a 9.

Unidade: mês.

GpuSpec

List

Não

Sim

Especificações das instâncias GPU do workspace.

Nenhuma

GpuSubscription

Map

Não

Sim

Configuração de assinatura de GPU.

Esta configuração entra em vigor após a criação do workspace. Para mais informações, consulte GpuSubscription properties.

IpWhiteList

List

Não

Sim

Lista de permissões de endereços IP do workspace.

Esta configuração entra em vigor após a criação do workspace.

PaymentDurationUnit

String

Não

Não

Unidade da duração da assinatura.

Valores válidos:

  • MONTH

ReleaseType

String

Não

Não

Tipo de liberação do workspace.

Nenhuma

ResourceGroupId

String

Não

Sim

ID do grupo de recursos.

Nenhuma

Subscription

Map

Não

Sim

Configuração para converter um workspace de pagamento conforme o uso em um workspace por assinatura.

Esta configuração entra em vigor após a criação do workspace. Para mais informações, consulte Subscription properties.

Tags

List

Não

Não

Tags a adicionar ao workspace.

É possível adicionar até 20 tags durante a criação do workspace. Para mais informações, consulte Tags properties.

Sintaxe de ResourceSpec

"ResourceSpec": {
  "Cu": String,
  "Gpu": Integer
}

Propriedades de ResourceSpec

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

Cu

String

Sim

Não

Número máximo de unidades de computação.

Intervalo válido: 1 a 9.

Gpu

Integer

Não

Não

Quantidade de GPUs.

Valor mínimo: 0.

Sintaxe de GpuSubscription

"GpuSubscription": {
  "InstanceId": String,
  "AutoRenew": Boolean,
  "PaymentDurationUnit": String,
  "InstanceTypeId": String,
  "Duration": Integer,
  "Operation": String,
  "GpuMachineNum": Integer
}

Propriedades de GpuSubscription

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

AutoRenew

Boolean

Não

Não

Define se a renovação automática está ativada.

Nenhuma

Duration

Integer

Não

Não

Duração da assinatura.

Valor mínimo: 1.

GpuMachineNum

Integer

Não

Não

Quantidade de máquinas GPU.

Valor mínimo: 1.

InstanceId

String

Não

Não

ID da instância de assinatura GPU.

Nenhuma

InstanceTypeId

String

Não

Não

Especificação da instância GPU.

Nenhuma

Operation

String

Não

Não

Tipo de operação.

Valores válidos:

  • BUY

  • UPGRADE

PaymentDurationUnit

String

Não

Não

Unidade da duração da assinatura.

Valores válidos:

  • MONTH

Sintaxe de Subscription

"Subscription": {
  "AutoRenewPeriod": String,
  "AutoRenew": Boolean,
  "PaymentDurationUnit": String,
  "Duration": String,
  "Queue": List,
  "AutoRenewPeriodUnit": String
}

Propriedades de Subscription

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

AutoRenew

Boolean

Não

Não

Define se a renovação automática está ativada.

Nenhuma

AutoRenewPeriod

String

Não

Não

Período de renovação automática.

Intervalo válido: 1 a 9.

Unidade: mês.

AutoRenewPeriodUnit

String

Não

Não

Unidade do período de renovação automática.

Valores válidos:

  • MONTH

Duration

String

Não

Não

Duração da assinatura.

Intervalo válido: 1 a 9.

Unidade: mês.

PaymentDurationUnit

String

Não

Não

Unidade da duração da assinatura.

Valores válidos:

  • MONTH

Queue

List

Não

Não

Filas para conversão ao plano de assinatura.

Nenhuma

Sintaxe de Tags

"Tags": [
  {
    "Value": String,
    "Key": String
  }
]

Propriedades de Tags

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

Key

String

Sim

Não

Chave da tag.

Nenhuma

Value

String

Não

Não

Valor da tag.

Nenhuma

Valores de retorno

Fn::GetAtt

  • Storage: caminho de armazenamento OSS do workspace.

  • WorkspaceId: ID do workspace.

Exemplos

Cenário 1: Criar um workspace Spark com base em recursos existentes

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 基于已有的OSS存储桶和RAM角色创建一个简单的EMR Serverless Spark工作空间。
  en: Create a simple EMR Serverless Spark workspace based on an existing OSS bucket and RAM role.
Parameters:
  WorkspaceName:
    Type: String
    Label:
      zh-cn: 工作空间名称
      en: Workspace Name
    Description:
      zh-cn: Spark工作空间名称,1-64个字符,支持中文、字母、数字、短划线和下划线。
      en: Spark workspace name, 1-64 characters. Supports Chinese, letters, digits, hyphens and underscores.
    MinLength: 1
    MaxLength: 64
    Default: my-spark-workspace
  OssBucketPath:
    Type: String
    Label:
      zh-cn: OSS存储路径
      en: OSS Bucket Path
    Description:
      zh-cn: 工作空间的OSS存储路径,格式为 oss://bucket-name/path/。
      en: 'The OSS storage path of the workspace, format: oss://bucket-name/path/.'
  RamRoleName:
    Type: String
    Label:
      zh-cn: RAM角色名称
      en: RAM Role Name
    Description:
      zh-cn: 用于运行Spark作业的RAM角色名称。
      en: The RAM role name used to run Spark jobs.
  Cu:
    Type: String
    Label:
      zh-cn: 计算单元(CU)
      en: Compute Units (CU)
    Description:
      zh-cn: 工作空间的最大计算单元数量。
      en: The maximum number of compute units for the workspace.
    Default: '10'
Resources:
  SparkWorkspace:
    Type: ALIYUN::EMR::SparkWorkspace
    Properties:
      WorkspaceName:
        Ref: WorkspaceName
      OssBucket:
        Ref: OssBucketPath
      RamRoleName:
        Ref: RamRoleName
      PaymentType: PayAsYouGo
      ResourceSpec:
        Cu:
          Ref: Cu
Outputs:
  WorkspaceId:
    Description:
      zh-cn: 工作空间ID。
      en: Workspace ID.
    Label:
      zh-cn: 工作空间ID
      en: Workspace ID
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - WorkspaceId
  Storage:
    Description:
      zh-cn: 工作空间的OSS存储路径。
      en: The OSS storage path of the workspace.
    Label:
      zh-cn: OSS存储路径
      en: Storage Path
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - Storage
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - WorkspaceName
          - OssBucketPath
          - RamRoleName
          - Cu
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "基于已有的OSS存储桶和RAM角色创建一个简单的EMR Serverless Spark工作空间。",
    "en": "Create a simple EMR Serverless Spark workspace based on an existing OSS bucket and RAM role."
  },
  "Parameters": {
    "WorkspaceName": {
      "Type": "String",
      "Label": {
        "zh-cn": "工作空间名称",
        "en": "Workspace Name"
      },
      "Description": {
        "zh-cn": "Spark工作空间名称,1-64个字符,支持中文、字母、数字、短划线和下划线。",
        "en": "Spark workspace name, 1-64 characters. Supports Chinese, letters, digits, hyphens and underscores."
      },
      "MinLength": 1,
      "MaxLength": 64,
      "Default": "my-spark-workspace"
    },
    "OssBucketPath": {
      "Type": "String",
      "Label": {
        "zh-cn": "OSS存储路径",
        "en": "OSS Bucket Path"
      },
      "Description": {
        "zh-cn": "工作空间的OSS存储路径,格式为 oss://bucket-name/path/。",
        "en": "The OSS storage path of the workspace, format: oss://bucket-name/path/."
      }
    },
    "RamRoleName": {
      "Type": "String",
      "Label": {
        "zh-cn": "RAM角色名称",
        "en": "RAM Role Name"
      },
      "Description": {
        "zh-cn": "用于运行Spark作业的RAM角色名称。",
        "en": "The RAM role name used to run Spark jobs."
      }
    },
    "Cu": {
      "Type": "String",
      "Label": {
        "zh-cn": "计算单元(CU)",
        "en": "Compute Units (CU)"
      },
      "Description": {
        "zh-cn": "工作空间的最大计算单元数量。",
        "en": "The maximum number of compute units for the workspace."
      },
      "Default": "10"
    }
  },
  "Resources": {
    "SparkWorkspace": {
      "Type": "ALIYUN::EMR::SparkWorkspace",
      "Properties": {
        "WorkspaceName": {
          "Ref": "WorkspaceName"
        },
        "OssBucket": {
          "Ref": "OssBucketPath"
        },
        "RamRoleName": {
          "Ref": "RamRoleName"
        },
        "PaymentType": "PayAsYouGo",
        "ResourceSpec": {
          "Cu": {
            "Ref": "Cu"
          }
        }
      }
    }
  },
  "Outputs": {
    "WorkspaceId": {
      "Description": {
        "zh-cn": "工作空间ID。",
        "en": "Workspace ID."
      },
      "Label": {
        "zh-cn": "工作空间ID",
        "en": "Workspace ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "WorkspaceId"
        ]
      }
    },
    "Storage": {
      "Description": {
        "zh-cn": "工作空间的OSS存储路径。",
        "en": "The OSS storage path of the workspace."
      },
      "Label": {
        "zh-cn": "OSS存储路径",
        "en": "Storage Path"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "Storage"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "WorkspaceName",
            "OssBucketPath",
            "RamRoleName",
            "Cu"
          ]
        }
      ]
    }
  }
}

Cenário 2: Criar bucket OSS, função RAM e workspace Spark

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建OSS存储桶、RAM角色和EMR Serverless Spark工作空间,配置IP白名单、GPU规格和标签,实现完整的Spark计算环境。
  en: Create an OSS bucket, RAM role, and EMR Serverless Spark workspace with IP whitelist, GPU specification, and tags for a complete Spark computing environment.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: 资源名称前缀
      en: Resource Name Prefix
    Description:
      zh-cn: 所有资源名称的统一前缀。
      en: Unified name prefix for all resources.
    Default: spark-env
    MinLength: 1
    MaxLength: 50
  Cu:
    Type: String
    Label:
      zh-cn: 计算单元(CU)
      en: Compute Units (CU)
    Description:
      zh-cn: 工作空间的最大计算单元数量。
      en: The maximum number of compute units for the workspace.
    Default: '20'
  GpuCount:
    Type: Number
    Label:
      zh-cn: GPU数量
      en: GPU Count
    Description:
      zh-cn: 工作空间的GPU数量,0表示不使用GPU。
      en: The number of GPUs for the workspace. 0 means no GPU.
    Default: 0
    MinValue: 0
Resources:
  OssBucket:
    Type: ALIYUN::OSS::Bucket
    Properties:
      BucketName:
        Fn::Sub: ${CommonName}-${ALIYUN::AccountId}
      AccessControl: private
      DeletionForce: true
      Tags:
        CreatedBy: ROS
        Purpose: SparkWorkspace
  RamRole:
    Type: ALIYUN::RAM::Role
    Properties:
      RoleName:
        Fn::Sub: ${CommonName}-spark-role
      Description: RAM role for EMR Serverless Spark
      AssumeRolePolicyDocument:
        Version: '1'
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - emr-serverless-spark.aliyuncs.com
      Policies:
        - PolicyName: AliyunEMRServerlessSparkFullAccess
          PolicyDocument:
            Version: '1'
            Statement:
              - Action:
                  - oss:GetObject
                  - oss:PutObject
                  - oss:DeleteObject
                  - oss:ListObjects
                  - oss:AbortMultipartUpload
                  - oss:ListMultipartUploads
                Resource:
                  - Fn::Sub: acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}
                  - Fn::Sub: acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}/*
                Effect: Allow
  SparkWorkspace:
    Type: ALIYUN::EMR::SparkWorkspace
    DependsOn:
      - OssBucket
      - RamRole
    Properties:
      WorkspaceName:
        Fn::Sub: ${CommonName}-workspace
      OssBucket:
        Fn::Sub: oss://${CommonName}-${ALIYUN::AccountId}/spark-workspace/
      RamRoleName:
        Ref: RamRole
      PaymentType: PayAsYouGo
      ResourceSpec:
        Cu:
          Ref: Cu
        Gpu:
          Ref: GpuCount
      AutoStartSessionCluster: true
      Tags:
        - Key: Environment
          Value: Development
        - Key: Team
          Value: DataEngineering
        - Key: CreatedBy
          Value: ROS
Outputs:
  WorkspaceId:
    Description:
      zh-cn: 工作空间ID。
      en: Workspace ID.
    Label:
      zh-cn: 工作空间ID
      en: Workspace ID
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - WorkspaceId
  Storage:
    Description:
      zh-cn: 工作空间的OSS存储路径。
      en: The OSS storage path of the workspace.
    Label:
      zh-cn: OSS存储路径
      en: Storage Path
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - Storage
  OssBucketName:
    Description:
      zh-cn: OSS存储桶名称。
      en: OSS bucket name.
    Label:
      zh-cn: OSS存储桶名称
      en: OSS Bucket Name
    Value:
      Fn::GetAtt:
        - OssBucket
        - Name
  RamRoleArn:
    Description:
      zh-cn: RAM角色ARN。
      en: RAM role ARN.
    Label:
      zh-cn: RAM角色ARN
      en: RAM Role ARN
    Value:
      Fn::GetAtt:
        - RamRole
        - Arn
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - Cu
          - GpuCount
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建OSS存储桶、RAM角色和EMR Serverless Spark工作空间,配置IP白名单、GPU规格和标签,实现完整的Spark计算环境。",
    "en": "Create an OSS bucket, RAM role, and EMR Serverless Spark workspace with IP whitelist, GPU specification, and tags for a complete Spark computing environment."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "资源名称前缀",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "所有资源名称的统一前缀。",
        "en": "Unified name prefix for all resources."
      },
      "Default": "spark-env",
      "MinLength": 1,
      "MaxLength": 50
    },
    "Cu": {
      "Type": "String",
      "Label": {
        "zh-cn": "计算单元(CU)",
        "en": "Compute Units (CU)"
      },
      "Description": {
        "zh-cn": "工作空间的最大计算单元数量。",
        "en": "The maximum number of compute units for the workspace."
      },
      "Default": "20"
    },
    "GpuCount": {
      "Type": "Number",
      "Label": {
        "zh-cn": "GPU数量",
        "en": "GPU Count"
      },
      "Description": {
        "zh-cn": "工作空间的GPU数量,0表示不使用GPU。",
        "en": "The number of GPUs for the workspace. 0 means no GPU."
      },
      "Default": 0,
      "MinValue": 0
    }
  },
  "Resources": {
    "OssBucket": {
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "BucketName": {
          "Fn::Sub": "${CommonName}-${ALIYUN::AccountId}"
        },
        "AccessControl": "private",
        "DeletionForce": true,
        "Tags": {
          "CreatedBy": "ROS",
          "Purpose": "SparkWorkspace"
        }
      }
    },
    "RamRole": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": {
          "Fn::Sub": "${CommonName}-spark-role"
        },
        "Description": "RAM role for EMR Serverless Spark",
        "AssumeRolePolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "emr-serverless-spark.aliyuncs.com"
                ]
              }
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": "AliyunEMRServerlessSparkFullAccess",
            "PolicyDocument": {
              "Version": "1",
              "Statement": [
                {
                  "Action": [
                    "oss:GetObject",
                    "oss:PutObject",
                    "oss:DeleteObject",
                    "oss:ListObjects",
                    "oss:AbortMultipartUpload",
                    "oss:ListMultipartUploads"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": "acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}"
                    },
                    {
                      "Fn::Sub": "acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}/*"
                    }
                  ],
                  "Effect": "Allow"
                }
              ]
            }
          }
        ]
      }
    },
    "SparkWorkspace": {
      "Type": "ALIYUN::EMR::SparkWorkspace",
      "DependsOn": [
        "OssBucket",
        "RamRole"
      ],
      "Properties": {
        "WorkspaceName": {
          "Fn::Sub": "${CommonName}-workspace"
        },
        "OssBucket": {
          "Fn::Sub": "oss://${CommonName}-${ALIYUN::AccountId}/spark-workspace/"
        },
        "RamRoleName": {
          "Ref": "RamRole"
        },
        "PaymentType": "PayAsYouGo",
        "ResourceSpec": {
          "Cu": {
            "Ref": "Cu"
          },
          "Gpu": {
            "Ref": "GpuCount"
          }
        },
        "AutoStartSessionCluster": true,
        "Tags": [
          {
            "Key": "Environment",
            "Value": "Development"
          },
          {
            "Key": "Team",
            "Value": "DataEngineering"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    }
  },
  "Outputs": {
    "WorkspaceId": {
      "Description": {
        "zh-cn": "工作空间ID。",
        "en": "Workspace ID."
      },
      "Label": {
        "zh-cn": "工作空间ID",
        "en": "Workspace ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "WorkspaceId"
        ]
      }
    },
    "Storage": {
      "Description": {
        "zh-cn": "工作空间的OSS存储路径。",
        "en": "The OSS storage path of the workspace."
      },
      "Label": {
        "zh-cn": "OSS存储路径",
        "en": "Storage Path"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "Storage"
        ]
      }
    },
    "OssBucketName": {
      "Description": {
        "zh-cn": "OSS存储桶名称。",
        "en": "OSS bucket name."
      },
      "Label": {
        "zh-cn": "OSS存储桶名称",
        "en": "OSS Bucket Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "OssBucket",
          "Name"
        ]
      }
    },
    "RamRoleArn": {
      "Description": {
        "zh-cn": "RAM角色ARN。",
        "en": "RAM role ARN."
      },
      "Label": {
        "zh-cn": "RAM角色ARN",
        "en": "RAM Role ARN"
      },
      "Value": {
        "Fn::GetAtt": [
          "RamRole",
          "Arn"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "Cu",
            "GpuCount"
          ]
        }
      ]
    }
  }
}

Cenário 3: Criar uma plataforma completa de análise de dados Spark

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 创建完整的EMR Serverless Spark数据分析平台,包含OSS存储桶、RAM角色、Spark工作空间(GPU加速+IP白名单+自动续费)、Livy网关(自动启停+公网访问),实现端到端的Spark大数据计算与交互式分析。
  en: Create a complete EMR Serverless Spark data analysis platform including OSS bucket, RAM role, Spark workspace with GPU acceleration and IP whitelist, and Livy gateway with auto start/stop and public access for end-to-end Spark big data computing and interactive analysis.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: 资源名称前缀
      en: Resource Name Prefix
    Description:
      zh-cn: 所有资源名称的统一前缀。
      en: Unified name prefix for all resources.
    Default: spark-platform
    MinLength: 1
    MaxLength: 50
  Cu:
    Type: String
    Label:
      zh-cn: 计算单元(CU)
      en: Compute Units (CU)
    Description:
      zh-cn: 工作空间的最大计算单元数量。
      en: The maximum number of compute units for the workspace.
    Default: '50'
  GpuCount:
    Type: Number
    Label:
      zh-cn: GPU数量
      en: GPU Count
    Description:
      zh-cn: 工作空间的GPU数量。
      en: The number of GPUs for the workspace.
    Default: 2
    MinValue: 0
  SparkEngineVersion:
    Type: String
    Label:
      zh-cn: Spark引擎版本
      en: Spark Engine Version
    Description:
      zh-cn: Livy网关使用的Spark引擎版本。
      en: The Spark engine version used by the Livy gateway.
    Default: esr-4.2.0
  LivyCpuLimit:
    Type: String
    Label:
      zh-cn: Livy CPU核数
      en: Livy CPU Cores
    Description:
      zh-cn: Livy服务器的CPU核数。
      en: The number of CPU cores for the Livy server.
    AllowedValues:
      - '1'
      - '2'
      - '4'
    Default: '2'
  LivyMemoryLimit:
    Type: String
    Label:
      zh-cn: Livy内存大小
      en: Livy Memory Size
    Description:
      zh-cn: Livy服务器的内存大小。
      en: The memory size of the Livy server.
    AllowedValues:
      - 4Gi
      - 8Gi
      - 16Gi
    Default: 8Gi
  LivyIdleTimeoutMinutes:
    Type: Number
    Label:
      zh-cn: Livy空闲超时(分钟)
      en: Livy Idle Timeout (Minutes)
    Description:
      zh-cn: Livy网关空闲超时后自动停止的时间。
      en: The idle timeout in minutes before the Livy gateway automatically stops.
    Default: 60
    MinValue: 1
  EnableLivyPublicAccess:
    Type: String
    Label:
      zh-cn: 是否开启Livy公网访问
      en: Enable Livy Public Access
    Description:
      zh-cn: 是否为Livy网关开启公网访问端点。
      en: Whether to enable public endpoint for the Livy gateway.
    AllowedValues:
      - 'true'
      - 'false'
    Default: 'false'
Conditions:
  EnablePublic:
    Fn::Equals:
      - Ref: EnableLivyPublicAccess
      - 'true'
Resources:
  OssBucket:
    Type: ALIYUN::OSS::Bucket
    Properties:
      BucketName:
        Fn::Sub: ${CommonName}-${ALIYUN::AccountId}
      AccessControl: private
      DeletionForce: true
      ServerSideEncryptionConfiguration:
        SSEAlgorithm: AES256
      Tags:
        CreatedBy: ROS
        Purpose: SparkPlatform
  RamRole:
    Type: ALIYUN::RAM::Role
    Properties:
      RoleName:
        Fn::Sub: ${CommonName}-spark-role
      Description: RAM role for EMR Serverless Spark platform
      AssumeRolePolicyDocument:
        Version: '1'
        Statement:
          - Action: sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - emr-serverless-spark.aliyuncs.com
      Policies:
        - PolicyName: AliyunEMRServerlessSparkFullAccess
          PolicyDocument:
            Version: '1'
            Statement:
              - Action:
                  - oss:GetObject
                  - oss:PutObject
                  - oss:DeleteObject
                  - oss:ListObjects
                  - oss:AbortMultipartUpload
                  - oss:ListMultipartUploads
                  - oss:GetBucketInfo
                Resource:
                  - Fn::Sub: acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}
                  - Fn::Sub: acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}/*
                Effect: Allow
  SparkWorkspace:
    Type: ALIYUN::EMR::SparkWorkspace
    DependsOn:
      - OssBucket
      - RamRole
    Properties:
      WorkspaceName:
        Fn::Sub: ${CommonName}-workspace
      OssBucket:
        Fn::Sub: oss://${CommonName}-${ALIYUN::AccountId}/spark-workspace/
      RamRoleName:
        Ref: RamRole
      PaymentType: PayAsYouGo
      ResourceSpec:
        Cu:
          Ref: Cu
        Gpu:
          Ref: GpuCount
      AutoStartSessionCluster: true
      Subscription:
        AutoRenew: true
        AutoRenewPeriod: '1'
        AutoRenewPeriodUnit: MONTH
        PaymentDurationUnit: MONTH
        Duration: '1'
      Tags:
        - Key: Environment
          Value: Production
        - Key: Team
          Value: DataEngineering
        - Key: CreatedBy
          Value: ROS
        - Key: CostCenter
          Value: BigData
  LivyGateway:
    Type: ALIYUN::EMR::LivyCompute
    DependsOn: SparkWorkspace
    Properties:
      WorkspaceBizId:
        Fn::GetAtt:
          - SparkWorkspace
          - WorkspaceId
      Name:
        Fn::Sub: ${CommonName}-livy
      DisplayReleaseVersion:
        Ref: SparkEngineVersion
      LivyVersion: 0.8.0
      AuthType: Token
      CpuLimit:
        Ref: LivyCpuLimit
      MemoryLimit:
        Ref: LivyMemoryLimit
      QueueName: root_queue
      EnablePublic:
        Ref: EnableLivyPublicAccess
      Fusion: true
      AutoStartConfiguration:
        Enable: true
      AutoStopConfiguration:
        Enable: true
        IdleTimeoutMinutes:
          Ref: LivyIdleTimeoutMinutes
Outputs:
  WorkspaceId:
    Description:
      zh-cn: Spark工作空间ID。
      en: Spark workspace ID.
    Label:
      zh-cn: 工作空间ID
      en: Workspace ID
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - WorkspaceId
  Storage:
    Description:
      zh-cn: 工作空间的OSS存储路径。
      en: The OSS storage path of the workspace.
    Label:
      zh-cn: OSS存储路径
      en: Storage Path
    Value:
      Fn::GetAtt:
        - SparkWorkspace
        - Storage
  OssBucketName:
    Description:
      zh-cn: OSS存储桶名称。
      en: OSS bucket name.
    Label:
      zh-cn: OSS存储桶名称
      en: OSS Bucket Name
    Value:
      Fn::GetAtt:
        - OssBucket
        - Name
  RamRoleArn:
    Description:
      zh-cn: RAM角色ARN。
      en: RAM role ARN.
    Label:
      zh-cn: RAM角色ARN
      en: RAM Role ARN
    Value:
      Fn::GetAtt:
        - RamRole
        - Arn
  LivyComputeId:
    Description:
      zh-cn: Livy网关ID。
      en: Livy gateway ID.
    Label:
      zh-cn: Livy网关ID
      en: Livy Gateway ID
    Value:
      Fn::GetAtt:
        - LivyGateway
        - LivyComputeId
  LivyStatus:
    Description:
      zh-cn: Livy网关状态。
      en: Livy gateway status.
    Label:
      zh-cn: Livy网关状态
      en: Livy Status
    Value:
      Fn::GetAtt:
        - LivyGateway
        - Status
  LivyEndpoint:
    Description:
      zh-cn: Livy网关公网访问地址。
      en: Livy gateway public endpoint.
    Label:
      zh-cn: Livy公网地址
      en: Livy Public Endpoint
    Value:
      Fn::GetAtt:
        - LivyGateway
        - Endpoint
  LivyEndpointInner:
    Description:
      zh-cn: Livy网关内网访问地址。
      en: Livy gateway internal endpoint.
    Label:
      zh-cn: Livy内网地址
      en: Livy Internal Endpoint
    Value:
      Fn::GetAtt:
        - LivyGateway
        - EndpointInner
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - Cu
          - GpuCount
      - Parameters:
          - SparkEngineVersion
          - LivyCpuLimit
          - LivyMemoryLimit
          - LivyIdleTimeoutMinutes
          - EnableLivyPublicAccess
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "创建完整的EMR Serverless Spark数据分析平台,包含OSS存储桶、RAM角色、Spark工作空间(GPU加速+IP白名单+自动续费)、Livy网关(自动启停+公网访问),实现端到端的Spark大数据计算与交互式分析。",
    "en": "Create a complete EMR Serverless Spark data analysis platform including OSS bucket, RAM role, Spark workspace with GPU acceleration and IP whitelist, and Livy gateway with auto start/stop and public access for end-to-end Spark big data computing and interactive analysis."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "资源名称前缀",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "所有资源名称的统一前缀。",
        "en": "Unified name prefix for all resources."
      },
      "Default": "spark-platform",
      "MinLength": 1,
      "MaxLength": 50
    },
    "Cu": {
      "Type": "String",
      "Label": {
        "zh-cn": "计算单元(CU)",
        "en": "Compute Units (CU)"
      },
      "Description": {
        "zh-cn": "工作空间的最大计算单元数量。",
        "en": "The maximum number of compute units for the workspace."
      },
      "Default": "50"
    },
    "GpuCount": {
      "Type": "Number",
      "Label": {
        "zh-cn": "GPU数量",
        "en": "GPU Count"
      },
      "Description": {
        "zh-cn": "工作空间的GPU数量。",
        "en": "The number of GPUs for the workspace."
      },
      "Default": 2,
      "MinValue": 0
    },
    "SparkEngineVersion": {
      "Type": "String",
      "Label": {
        "zh-cn": "Spark引擎版本",
        "en": "Spark Engine Version"
      },
      "Description": {
        "zh-cn": "Livy网关使用的Spark引擎版本。",
        "en": "The Spark engine version used by the Livy gateway."
      },
      "Default": "esr-4.2.0"
    },
    "LivyCpuLimit": {
      "Type": "String",
      "Label": {
        "zh-cn": "Livy CPU核数",
        "en": "Livy CPU Cores"
      },
      "Description": {
        "zh-cn": "Livy服务器的CPU核数。",
        "en": "The number of CPU cores for the Livy server."
      },
      "AllowedValues": [
        "1",
        "2",
        "4"
      ],
      "Default": "2"
    },
    "LivyMemoryLimit": {
      "Type": "String",
      "Label": {
        "zh-cn": "Livy内存大小",
        "en": "Livy Memory Size"
      },
      "Description": {
        "zh-cn": "Livy服务器的内存大小。",
        "en": "The memory size of the Livy server."
      },
      "AllowedValues": [
        "4Gi",
        "8Gi",
        "16Gi"
      ],
      "Default": "8Gi"
    },
    "LivyIdleTimeoutMinutes": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Livy空闲超时(分钟)",
        "en": "Livy Idle Timeout (Minutes)"
      },
      "Description": {
        "zh-cn": "Livy网关空闲超时后自动停止的时间。",
        "en": "The idle timeout in minutes before the Livy gateway automatically stops."
      },
      "Default": 60,
      "MinValue": 1
    },
    "EnableLivyPublicAccess": {
      "Type": "String",
      "Label": {
        "zh-cn": "是否开启Livy公网访问",
        "en": "Enable Livy Public Access"
      },
      "Description": {
        "zh-cn": "是否为Livy网关开启公网访问端点。",
        "en": "Whether to enable public endpoint for the Livy gateway."
      },
      "AllowedValues": [
        "true",
        "false"
      ],
      "Default": "false"
    }
  },
  "Conditions": {
    "EnablePublic": {
      "Fn::Equals": [
        {
          "Ref": "EnableLivyPublicAccess"
        },
        "true"
      ]
    }
  },
  "Resources": {
    "OssBucket": {
      "Type": "ALIYUN::OSS::Bucket",
      "Properties": {
        "BucketName": {
          "Fn::Sub": "${CommonName}-${ALIYUN::AccountId}"
        },
        "AccessControl": "private",
        "DeletionForce": true,
        "ServerSideEncryptionConfiguration": {
          "SSEAlgorithm": "AES256"
        },
        "Tags": {
          "CreatedBy": "ROS",
          "Purpose": "SparkPlatform"
        }
      }
    },
    "RamRole": {
      "Type": "ALIYUN::RAM::Role",
      "Properties": {
        "RoleName": {
          "Fn::Sub": "${CommonName}-spark-role"
        },
        "Description": "RAM role for EMR Serverless Spark platform",
        "AssumeRolePolicyDocument": {
          "Version": "1",
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "emr-serverless-spark.aliyuncs.com"
                ]
              }
            }
          ]
        },
        "Policies": [
          {
            "PolicyName": "AliyunEMRServerlessSparkFullAccess",
            "PolicyDocument": {
              "Version": "1",
              "Statement": [
                {
                  "Action": [
                    "oss:GetObject",
                    "oss:PutObject",
                    "oss:DeleteObject",
                    "oss:ListObjects",
                    "oss:AbortMultipartUpload",
                    "oss:ListMultipartUploads",
                    "oss:GetBucketInfo"
                  ],
                  "Resource": [
                    {
                      "Fn::Sub": "acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}"
                    },
                    {
                      "Fn::Sub": "acs:oss:*:*:${CommonName}-${ALIYUN::AccountId}/*"
                    }
                  ],
                  "Effect": "Allow"
                }
              ]
            }
          }
        ]
      }
    },
    "SparkWorkspace": {
      "Type": "ALIYUN::EMR::SparkWorkspace",
      "DependsOn": [
        "OssBucket",
        "RamRole"
      ],
      "Properties": {
        "WorkspaceName": {
          "Fn::Sub": "${CommonName}-workspace"
        },
        "OssBucket": {
          "Fn::Sub": "oss://${CommonName}-${ALIYUN::AccountId}/spark-workspace/"
        },
        "RamRoleName": {
          "Ref": "RamRole"
        },
        "PaymentType": "PayAsYouGo",
        "ResourceSpec": {
          "Cu": {
            "Ref": "Cu"
          },
          "Gpu": {
            "Ref": "GpuCount"
          }
        },
        "AutoStartSessionCluster": true,
        "Subscription": {
          "AutoRenew": true,
          "AutoRenewPeriod": "1",
          "AutoRenewPeriodUnit": "MONTH",
          "PaymentDurationUnit": "MONTH",
          "Duration": "1"
        },
        "Tags": [
          {
            "Key": "Environment",
            "Value": "Production"
          },
          {
            "Key": "Team",
            "Value": "DataEngineering"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          },
          {
            "Key": "CostCenter",
            "Value": "BigData"
          }
        ]
      }
    },
    "LivyGateway": {
      "Type": "ALIYUN::EMR::LivyCompute",
      "DependsOn": "SparkWorkspace",
      "Properties": {
        "WorkspaceBizId": {
          "Fn::GetAtt": [
            "SparkWorkspace",
            "WorkspaceId"
          ]
        },
        "Name": {
          "Fn::Sub": "${CommonName}-livy"
        },
        "DisplayReleaseVersion": {
          "Ref": "SparkEngineVersion"
        },
        "LivyVersion": "0.8.0",
        "AuthType": "Token",
        "CpuLimit": {
          "Ref": "LivyCpuLimit"
        },
        "MemoryLimit": {
          "Ref": "LivyMemoryLimit"
        },
        "QueueName": "root_queue",
        "EnablePublic": {
          "Ref": "EnableLivyPublicAccess"
        },
        "Fusion": true,
        "AutoStartConfiguration": {
          "Enable": true
        },
        "AutoStopConfiguration": {
          "Enable": true,
          "IdleTimeoutMinutes": {
            "Ref": "LivyIdleTimeoutMinutes"
          }
        }
      }
    }
  },
  "Outputs": {
    "WorkspaceId": {
      "Description": {
        "zh-cn": "Spark工作空间ID。",
        "en": "Spark workspace ID."
      },
      "Label": {
        "zh-cn": "工作空间ID",
        "en": "Workspace ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "WorkspaceId"
        ]
      }
    },
    "Storage": {
      "Description": {
        "zh-cn": "工作空间的OSS存储路径。",
        "en": "The OSS storage path of the workspace."
      },
      "Label": {
        "zh-cn": "OSS存储路径",
        "en": "Storage Path"
      },
      "Value": {
        "Fn::GetAtt": [
          "SparkWorkspace",
          "Storage"
        ]
      }
    },
    "OssBucketName": {
      "Description": {
        "zh-cn": "OSS存储桶名称。",
        "en": "OSS bucket name."
      },
      "Label": {
        "zh-cn": "OSS存储桶名称",
        "en": "OSS Bucket Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "OssBucket",
          "Name"
        ]
      }
    },
    "RamRoleArn": {
      "Description": {
        "zh-cn": "RAM角色ARN。",
        "en": "RAM role ARN."
      },
      "Label": {
        "zh-cn": "RAM角色ARN",
        "en": "RAM Role ARN"
      },
      "Value": {
        "Fn::GetAtt": [
          "RamRole",
          "Arn"
        ]
      }
    },
    "LivyComputeId": {
      "Description": {
        "zh-cn": "Livy网关ID。",
        "en": "Livy gateway ID."
      },
      "Label": {
        "zh-cn": "Livy网关ID",
        "en": "Livy Gateway ID"
      },
      "Value": {
        "Fn::GetAtt": [
          "LivyGateway",
          "LivyComputeId"
        ]
      }
    },
    "LivyStatus": {
      "Description": {
        "zh-cn": "Livy网关状态。",
        "en": "Livy gateway status."
      },
      "Label": {
        "zh-cn": "Livy网关状态",
        "en": "Livy Status"
      },
      "Value": {
        "Fn::GetAtt": [
          "LivyGateway",
          "Status"
        ]
      }
    },
    "LivyEndpoint": {
      "Description": {
        "zh-cn": "Livy网关公网访问地址。",
        "en": "Livy gateway public endpoint."
      },
      "Label": {
        "zh-cn": "Livy公网地址",
        "en": "Livy Public Endpoint"
      },
      "Value": {
        "Fn::GetAtt": [
          "LivyGateway",
          "Endpoint"
        ]
      }
    },
    "LivyEndpointInner": {
      "Description": {
        "zh-cn": "Livy网关内网访问地址。",
        "en": "Livy gateway internal endpoint."
      },
      "Label": {
        "zh-cn": "Livy内网地址",
        "en": "Livy Internal Endpoint"
      },
      "Value": {
        "Fn::GetAtt": [
          "LivyGateway",
          "EndpointInner"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "Cu",
            "GpuCount"
          ]
        },
        {
          "Parameters": [
            "SparkEngineVersion",
            "LivyCpuLimit",
            "LivyMemoryLimit",
            "LivyIdleTimeoutMinutes",
            "EnableLivyPublicAccess"
          ]
        }
      ]
    }
  }
}