Amazon web services 如何从shell脚本捕获Spark错误

Amazon web services 如何从shell脚本捕获Spark错误,amazon-web-services,apache-spark,amazon-data-pipeline,Amazon Web Services,Apache Spark,Amazon Data Pipeline,我在AWS数据管道中有一个管道,它运行一个名为shell.sh的shell脚本: $ spark-submit transform_json.py Running command on cluster... [54.144.10.162] Running command... [52.206.87.30] Running command... [54.144.10.162] Command complete. [52.206.87.30] Command complete. run_comm

我在AWS数据管道中有一个管道,它运行一个名为shell.sh的shell脚本:

$ spark-submit transform_json.py


Running command on cluster...
[54.144.10.162] Running command...
[52.206.87.30] Running command...
[54.144.10.162] Command complete.
[52.206.87.30] Command complete.
run_command finished in 0:00:06.
AWS数据管道控制台表示作业已“完成”,但在stderr日志中,我看到作业实际上已中止:

Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Status Code: 404, AWS Service: Amazon S3, AWS Request ID: xxxxx, AWS Error Code: null, AWS Error Message: Not Found...        
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 5.0 failed 1 times, most recent failure: Lost task 0.0 in stage 5.0 (TID 5, localhost, executor driver): org.apache.spark.SparkException: Task failed while writing rows.
    ...
        20/05/22 11:42:47 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
        20/05/22 11:42:47 INFO MemoryStore: MemoryStore cleared
        20/05/22 11:42:47 INFO BlockManager: BlockManager stopped
        20/05/22 11:42:47 INFO BlockManagerMaster: BlockManagerMaster stopped
        20/05/22 11:42:47 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
        20/05/22 11:42:47 INFO SparkContext: Successfully stopped SparkContext
        20/05/22 11:42:47 INFO ShutdownHookManager: Shutdown hook called

我对数据管道和Spark有些陌生;我不知道幕后到底发生了什么。如何让shell脚本捕获
SparkException

尝试下面的示例

您的shell脚本可以捕获如下错误代码。。。其中非零退出代码为错误

$?
是最近执行的命令的退出状态;按照惯例,0表示成功,其他任何东西都表示失败。


spark-submit transform_json.py


 ret_code=$?
   if [ $ret_code -ne 0 ]; then 
      exit $ret_code
   fi

在错误情况下,您必须通过
sys.exit(-1)
编码返回退出代码。检查此项以了解python异常处理


检查这个

你检查了吗?@HithamS.AlQadheeb实际上,我有。该线程没有讨论如何处理错误,只是为什么错误会首先发生。不幸的是,它不起作用,我仍在尝试一些事情错误是什么。。。要捕获退出代码,这是一种方法(即使对于scala或java也是如此…)。您必须做的一件事是,您必须在异常模块中使用非零退出代码退出。。。。如果您的python代码中有错误,请告诉我它是否适合您。如果是这样的话,您可以通过接受作为所有者的答案来关闭此线程。我想我能够找到答案,我在脚本的开头添加了“set-e”,并将命令保留为“spark submit transform_json.py”。它正在工作。谢谢你!