troubleshoot-spark-job
Diagnoses and fixes failed or slow Apache Spark workloads on AWS Glue, EMR on EC2, EMR Serverless, and EMR on EKS with the analyze_spark_workload MCP tool, which provides deeper analysis than the AWS job run APIs alone. Analyzes job failures, performance issues, and error stack traces, and generates
- 01Installs
- New
- 02Files scanned
- 2
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 abf62ec17a98c12a… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Diagnose failed or degraded Apache Spark workloads on AWS Glue, Amazon EMR on EC2, Amazon EMR Serverless, and Amazon EMR on EKS. Uses the SageMaker Unified Studio Spark Troubleshooting MCP server (spark-troubleshooting) to analyze job logs, error traces, and resource metrics. Optionally follows up with the Spark Code Recommendation MCP server (spark-code-recommendation) to generate targeted code fixes - but only when the diagnosis identifies a code-level fix.
Reference Documentation
- error-handling.md -- MCP connection issues and setup guidance
Workflow
Constraints:
- You MUST call
analyze_spark_workload(thespark-troubleshootingserver) FIRST as the primary diagnostic tool for every troubleshooting request. It provides deeper analysis than AWS job run APIs alone. - You MUST NOT call
spark_code_recommendation(thespark-code-recommendationserver) standalone or as a first step. It is a FOLLOW-UP ONLY: invoke it afteranalyze_spark_workloadhas produced a diagnosis AND that diagnosis identifies a code-level fix AND the user wants code changes. Calling it without a prioranalyze_spark_workloaddiagnosis produces lower-quality root cause analysis. - You MUST NOT call
spark_code_recommendationwhen the diagnosed fix is configuration-only (e.g. memory, partition, or resource tuning with no code change). Present the configuration fix directly. - Prefer
analyze_spark_workload's natural chaining into code recommendation over an explicit standalonespark_code_recommendationcall. - Do NOT call
aws emr describe-step,aws emr describe-cluster,aws glue get-job-run,aws emr-serverless get-job-run,aws emr-containers describe-job-run, or any AWS CLI command as a diagnostic step. The MCP tool provides all the information needed. - Do NOT call
aws emr list-clusters,aws emr-serverless list-applications,aws emr-containers list-virtual-clusters,aws glue list-jobs,aws glue get-job-runs, or any discovery/list API. Ask the user for identifiers instead.
Phase 0: Gather Job Identifiers
If the user has not provided the required identifiers, ask for them. Do NOT call AWS CLI, AWS APIs, list-jobs, get-job-runs, or any other discovery API to look them up. Do NOT attempt to list recent failures or guess which job failed. Ask the user directly and wait for a response.
A bare "EMR" (without EC2, cluster, or step; Serverless or application; or EKS or virtual cluster) is NOT platform-distinguishing. If the user says only "EMR" (for example, "my EMR job failed"), ask whether it is EMR on EC2, EMR Serverless, or EMR on EKS before requesting identifiers; the three platforms use different identifiers.
AWS Glue: job name and job run ID (hex string starting with jr_)
EMR on EC2: cluster ID (format: j-<alphanumeric>, typically 12-13 chars after the prefix) and step ID (alphanumeric string starting with s-)
EMR Serverless: application ID (16-char alphanumeric string starting with 00) and job run ID (16-char alphanumeric string starting with 00)
EMR on EKS: virtual cluster ID (lowercase alphanumeric string, e.g. 6aycqwm1iryxff42j7sf1qix0) and job run ID (alphanumeric string, e.g. 00000003891im4vqfb6)
Optional for all platforms: additional context (error message, user observations, what was tried)
Phase 1: Analyze the Workload
Call analyze_spark_workload with the platform type and parameters. Valid platform_type values: GLUE, EMR_EC2, EMR_SERVERLESS, EMR_EKS. For EMR_EKS, pass virtual_cluster_id and job_run_id. The tool returns:
- Root cause classification (OOM, data skew, misconfiguration, code error, resource contention, etc.)
- Contributing factors with evidence from logs
- Severity assessment
- Recommended fixes with priority ordering
Phase 2: Present Diagnosis
Present the analysis results clearly:
- Root cause: Primary failure reason with supporting evidence
- Contributing factors: Secondary issues that worsened the failure
- Recommended fixes: Ordered by impact. Give specific values for configuration fixes. For code-level fixes, do not hand-write the code change here; generate it in Phase 3.
If - and only if - the diagnosis includes code-level issues: when the user has already asked for code fixes, go directly to Phase 3 and call spark_code_recommendation for the code change rather than writing it by hand; ask first only if the user has not requested code changes. If the fix is configuration-only, do not offer code recommendations; present the config change directly.
Phase 3: Generate Code Recommendations (Follow-up, conditional)
Enter this phase ONLY when Phase 1/2 diagnosed a code-level issue (inefficient transformations, missing optimizations, incorrect API usage) AND the user wants fixes. Call spark_code_recommendation with the analysis results and the user's Spark code. The tool generates specific code changes with before/after examples, configuration tuning recommendations, and explanations. Present the tool's code changes; do not substitute a hand-written fix for them.
Note: analyze_spark_workload may automatically invoke spark_code_recommendation when the error category is eligible - prefer this natural chaining over calling spark_code_recommendation independently, which produces lower-quality root cause analysis. If analyze_spark_workload did not return code recommendations, call spark_code_recommendation after the diagnosis. Never call spark_code_recommendation as the entry point to this skill.
Phase 4: Summarize and Next Steps
Provide a concise summary: root cause confirmed, fixes applied or recommended, configuration changes needed, whether a re-run is expected to succeed, and any follow-up monitoring recommended.
Argument Routing
- No args: Ask for platform and job identifiers interactively
- Platform specified: e.g.
glue my-etl-job jr_abc123-- Skip platform prompts
Supported Platforms
| Platform | Trigger Keywords |
|---|---|
| AWS Glue | glue job, glue etl, glue spark |
| EMR on EC2 | emr ec2, emr ec2 cluster, emr step |
| EMR Serverless | emr serverless, emr-s, serverless spark |
| EMR on EKS | emr on eks, emr eks, emr virtual cluster, emr-containers |
If the user's input matches a trigger keyword in the table above, use that platform directly. The fallback (asking which platform) applies only when no platform-distinguishing keyword is present. A bare "EMR" does not match any EMR row, so ask. If the input matches trigger keywords for more than one platform, ask the user which platform the failing job runs on before proceeding.
Gotchas
- Connecting to the MCP server and listing its tools requires no
sagemaker-unified-studio-mcpaction permissions. Permissions are required only when tools make downstream API calls (e.g., accessing Glue, EMR, or CloudWatch logs). If a tool call fails with AccessDeniedException, see the IAM setup docs. - EMR Serverless IDs are 16-character alphanumeric strings starting with
00(e.g.,00g5gmlv894uvl09), not the same format as EMR-EC2 step IDs. - EMR on EKS jobs are identified by virtual cluster ID + job run ID (the
emr-containersAPI), not by an EKS cluster name. Do NOT callaws emr-containers list-job-runsorkubectlto find them; ask the user. - The
--read-timeout 180is intentional -- log fetching and analysis for large jobs can take several minutes. - Code recommendations require the original Spark source code to be accessible. If the code is not local, provide the relevant file paths or paste the problematic sections.
- Do not enable "trust" for all tool calls by default. Review each tool execution before approving.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
| MCP server failed to load | Configuration or credentials issue | Verify JSON syntax and AWS credentials |
| AccessDeniedException on log fetch | IAM role lacks required permissions | Add the missing permissions (see IAM setup docs) |
| Job run not found | Incorrect job name, run ID, or wrong region | Verify identifiers with the user |
| Analysis returns no root cause | Logs unavailable or job succeeded | Confirm the job is in a failed state; check log retention settings |
Detailed guidance: references/error-handling.md
Files
2- SKILL.md
8bba9a3fbc9.3 KB - references/error-handling.md
1e1d9c2fa51.4 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from aws/agent-toolkit-for-aws8
Amazon Aurora MySQL — creates, modifies, and advises on Aurora MySQL clusters specifically (MySQL-compatible engine, Aurora serverless, parallel query). Trigger for Aurora MySQL cluster operations, ACU sizing, I/O-Optimized storage, commitment pricing, or MySQL upgrade planning. Aurora MySQL uses fu
Amazon Aurora PostgreSQL — creates, modifies, and advises on Aurora PostgreSQL clusters specifically (PostgreSQL-compatible engine, Aurora serverless, express configuration, pgvector, Babelfish). Trigger for Aurora PostgreSQL cluster operations, express-configuration quick-start, ACU sizing, I/O-Opt
Builds generative AI applications on Amazon Bedrock. Covers model invocation (Converse API, InvokeModel), RAG with Knowledge Bases, Bedrock Agents, Guardrails, and AgentCore (including the Harness managed agent loop). Applies when invoking models, setting up or migrating Knowledge Bases to Managed,
Runs quantum workflows on AWS / Amazon Braket: circuits and algorithms, QPU/device and ARN discovery, LocalSimulator, tasks, program sets, Hybrid Jobs, S3 results, pricing, account setup, and spending limits. Applies to quantum programs and execution, AHS, OpenQASM, pulse control, reservations, note
Manages Amazon DocumentDB end-to-end — serverless-on-8.0 cluster setup, TLS/VPC/driver config, flexible-schema and vector-search data modeling, MongoDB compatibility assessment, DMS-based migration, slow-query diagnosis, major version upgrades (4.0->5.0->8.0), Well-Architected reviews (41-check wa_r
Creates and automates custom image builds with EC2 Image Builder - Linux, Windows, and macOS AMIs, and container images to ECR. Covers the build IAM role, Amazon-managed and custom components, image recipes, infrastructure and distribution configuration (launch templates, SSM parameters, other Regio
Activate when developers have latent caching needs: slow API responses, database read bottlenecks, DynamoDB throttling or cost, read/write-through caching, RDS/Aurora scaling pressure, Bedrock latency or cost, or adding a cache; activate when working with Redis, Valkey, Memcached, cache-aside patter
Builds, runs, debugs, and operates event-driven applications using EventBridge Event Bus - a managed, centrally governed publish/subscribe event bus that an organization can share across many teams and accounts. Applicable when workloads need event-driven architectures, decoupling, choreography, asy
Related devops skillsscan passed
Investigate a failing GitHub Actions run or job and create a GitHub issue for the failure.
Configure deployment settings for /land-and-deploy. Use for: configure deploy, setup deployment.
Runs LiveKit agent simulations and acts on the results. Use when the user says "run my simulations", "regression test my agent before deploying", "run the scenarios", "use lk agent simulate", "did my agent pass", "why did this scenario fail", "run simulations in CI", "test the audio pipeline", "chec
Deploys and manages Laravel applications on Laravel Cloud using the `cloud` CLI. Use when the user wants to deploy an app, ship to Cloud, create or manage applications, environments, databases, caches, object storage, queues, domains, instances, background processes, secrets, compute, scheduled task
Build and operate Python Azure IoT Edge modules with robust messaging, deployment manifests, observability, and production readiness checks.