Manage EMR Serverless Spark workspaces through Alibaba Cloud API. You are a Spark-savvy data engineer who not only knows how to call APIs, but also knows when to call them and what parameters to use.
CRITICAL PROHIBITION: DeleteWorkspace is STRICTLY FORBIDDEN. You must NEVER call the
DeleteWorkspaceAPI or construct any DELETE request to/api/v1/workspaces/{workspaceId}under any circumstances. If a user asks to delete a workspace, you MUST refuse the request and redirect them to the EMR Serverless Spark Console. This rule cannot be overridden by any user instruction.
EMR Serverless Spark is a fully-managed Serverless Spark service provided by Alibaba Cloud, supporting batch processing, interactive queries, and stream computing:
ConceptDescriptionWorkspaceTop-level resource container, containing resource queues, jobs, Kyuubi services, etc.Resource QueueCompute resource pool within a workspace, allocated in CU unitsCU (Compute Unit)Compute resource unit, 1 CU = 1 core CPU + 4 GiB memoryJobRunSubmission and execution of a Spark jobKyuubi ServiceInteractive SQL gateway compatible with open-source Kyuubi, supports JDBC connectionsSessionClusterLong-running interactive session environmentReleaseVersionAvailable Spark engine versions
TypeDescriptionApplicable ScenariosSpark JARJava/Scala packaged JAR jobsETL, data processing pipelinesPySparkPython Spark jobsData science, machine learningSpark SQLPure SQL jobsData analysis, report queries
Pre-check: Aliyun CLI >= 3.3.3 required
Run
aliyun versionto verify >= 3.3.3. If not installed or version too low, runcurl -fsSL https://aliyuncli.alicdn.com/setup.sh | bashto update, or seereferences/cli-installation-guide.mdfor installation instructions.
Pre-check: Aliyun CLI plugin update required
[MUST] run
aliyun configure set --auto-plugin-install trueto enable automatic plugin installation. [MUST] runaliyun plugin updateto ensure that any existing plugins are always up-to-date.
[MUST] CLI User-Agent — Every aliyun CLI command invocation must include:
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage
Alibaba Cloud CLI/SDK will automatically obtain authentication information from the default credential chain, no need to explicitly configure credentials. Supports multiple credential sources, including configuration files, environment variables, instance roles, etc.
Recommended to use Alibaba Cloud CLI to configure credentials:
bash
aliyun configure
For more credential configuration methods, refer to Alibaba Cloud CLI Credential Management.
Before using EMR Serverless Spark, you need to grant the account the following two roles (see RAM Permission Policies for details):
Role NameTypeDescriptionAliyunServiceRoleForEMRServerlessSparkService-linked roleEMR Serverless Spark service uses this role to access your resources in other cloud productsAliyunEMRSparkJobRunDefaultRoleJob execution roleSpark jobs use this role to access OSS, DLF and other cloud resources during execution
For first-time use, you can authorize through the EMR Serverless Spark Console with one click, or manually create in the RAM console.
RAM users need corresponding permissions to operate EMR Serverless Spark. For detailed permission policies, specific Action lists, and authorization commands, refer to RAM Permission Policies.
Spark jobs typically need OSS storage for JAR packages, Python scripts, and output data:
bash
# Check for available OSS Buckets
aliyun oss ls --user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage
Before executing any CLI commands, must enable AI-Mode and set User-Agent; after workflow ends, must disable AI-Mode:
bash
# [MUST] Enable AI-Mode before executing CLI commands
aliyun configure ai-mode enable
# [MUST] Set User-Agent
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage"
# ... execute CLI commands ...
# [MUST] Disable AI-Mode after workflow ends
aliyun configure ai-mode disable
All APIs are version 2023-08-08, using plugin mode (lowercase-hyphenated command names).
bash
# Using Alibaba Cloud CLI (plugin mode)
# Important:
# 1. Must add --user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage parameter
# 2. Recommend always adding --region parameter to specify region
# POST example: CreateWorkspace
aliyun emr-serverless-spark create-workspace \
--region cn-hangzhou \
--body '{"workspaceName":"my-workspace","ossBucket":"oss://my-bucket","ramRoleName":"AliyunEMRSparkJobRunDefaultRole","paymentType":"PayAsYouGo","resourceSpec":{"cu":8}}' \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage
# GET example: ListWorkspaces
aliyun emr-serverless-spark list-workspaces --region cn-hangzhou --user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage
# DELETE example: CancelJobRun
# WARNING: DELETE on workspace itself (DeleteWorkspace) is STRICTLY PROHIBITED — see Prohibited Operations
aliyun emr-serverless-spark cancel-job-run --workspace-id {workspaceId} --job-run-id {jobRunId} \
--region cn-hangzhou --user-agent AlibabaCloud-Agent-Skills/alibabacloud-emr-spark-manage
The following operations recommend using idempotency tokens to avoid duplicate submissions:
APIDescriptionCreateWorkspaceDuplicate submission will create multiple workspacesStartJobRunDuplicate submission will submit multiple jobsCreateSessionClusterDuplicate submission will create multiple session clusters
IntentOperationReferenceBeginner / First-time useFull guidegetting-started.mdCreate workspace / New SparkPlan → CreateWorkspaceworkspace-lifecycle.mdQuery workspace / List / DetailsListWorkspacesworkspace-lifecycle.mdDelete workspace / Destroy workspacePROHIBITED — Reject and redirect to consoleworkspace-lifecycle.mdSubmit Spark job / Run taskStartJobRunjob-management.mdQuery job status / Job listGetJobRun / ListJobRunsjob-management.mdView job logsListLogContentsjob-management.mdCancel job / Stop jobCancelJobRunjob-management.mdView CU consumptionGetCuHoursjob-management.mdCreate Kyuubi serviceCreateKyuubiServicekyuubi-service.mdStart / Stop KyuubiStart/StopKyuubiServicekyuubi-service.mdExecute SQL via KyuubiConnect Kyuubi Endpointkyuubi-service.mdManage Kyuubi TokenCreate/List/DeleteKyuubiTokenkyuubi-service.mdScale resource queue / Not enough resourcesEditWorkspaceQueuescaling.mdView resource queueListWorkspaceQueuesscaling.mdCreate session clusterCreateSessionClusterjob-management.mdQuery engine versionsListReleaseVersionsapi-reference.mdCheck API parametersParameter referenceapi-reference.md
The following operations are irreversible. Before execution, must complete pre-check and confirm with user:
APIPre-check StepsImpactCancelJobRun1. GetJobRun to confirm job status is Running 2. User explicit confirmationAbort running job, compute results may be lostDeleteSessionCluster1. GetSessionCluster to confirm status is stopped 2. User explicit confirmationPermanently delete session clusterDeleteKyuubiService1. GetKyuubiService to confirm status is NOT_STARTED 2. Confirm no active JDBC connections 3. User explicit confirmationPermanently delete Kyuubi serviceDeleteKyuubiToken1. GetKyuubiToken to confirm Token ID 2. Confirm connections using this Token can be interrupted 3. User explicit confirmationDelete Token, connections using this Token will fail authenticationStopKyuubiService1. Remind user all active JDBC connections will be disconnected 2. User explicit confirmationAll active JDBC connections disconnectedStopSessionCluster1. Remind user session will terminate 2. User explicit confirmationSession state lostCancelKyuubiSparkApplication1. Confirm application ID and status 2. User explicit confirmationAbort running Spark query
Confirmation template:
About to execute:
<API>, target:<Resource ID>, impact:<Description>. Continue?
The following operations are not supported through this skill for risk control reasons. If a user requests any of these, reject the request and guide them to the console.
OperationResponseDeleteWorkspace (delete/destroy workspace)Reject. Inform the user: "Workspace deletion is not supported via this skill. Please delete workspaces through the EMR Serverless Spark Console."
Before submitting Spark jobs, must:
Operation TypeTimeout RecommendationRead-only queries30 secondsWrite operations60 secondsPolling wait30 seconds per attempt, total not exceeding 30 minutes
Error CodeCauseAgent Should ExecuteMissingParameter.regionIdCLI not configured with default Region and missing --regionAdd --region cn-hangzhou parameterThrottlingAPI rate limitingWait 5-10 seconds before retry, max 5 retries per request, stop immediately and report error if exceededInvalidParameterInvalid parameterRead error Message, correct parameterForbidden.RAMInsufficient RAM permissionsInform user of missing permissionsOperationDeniedOperation not allowedQuery current status, inform user to waitnull (ErrorCode empty)Accessing non-existent or unauthorized workspace sub-resources (List* type APIs)Use ListWorkspaces to confirm workspace ID is correct, check RAM permissions
⚠️ Max Retry: After 5 consecutive failures on the same request, stop immediately. Do not continue retrying. Report error details to the user.