我正在使用map
DynamicFrame 的方法(或者等效地,Map.apply
方法)。我注意到我传递给这些函数的函数中的任何错误都会被默默地忽略,并导致返回的 DynamicFrame 为空。
假设我有一个这样的作业脚本:
import sys
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.transforms import *
glueContext = GlueContext(SparkContext.getOrCreate())
dyF = glueContext.create_dynamic_frame.from_catalog(database="radixdemo", table_name="census_csv")
def my_mapper(rec):
import logging
logging.error("[RADIX] An error-log from in the mapper!")
print "[RADIX] from in the mapper!"
raise Exception("[RADIX] A bug!")
dyF = dyF.map(my_mapper, 'my_mapper')
print "Count: ", dyF.count()
dyF.printSchema()
dyF.toDF().show()
如果我在 Glue Dev Endpoint 中运行此脚本gluepython
,我得到这样的输出:
[glue@ip-172-31-83-196 ~]$ gluepython gluejob.py
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/share/aws/glue/etl/jars/glue-assembly.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
18/05/23 20:56:46 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Count: 0
root
++
||
++
++
关于此输出的注释:
- 我没有看到结果
print
声明或logging.error
陈述。
- 没有迹象表明
my_mapper
提出了一个例外。
- The
printSchema
调用显示生成的 DynamicFrame 上没有架构元数据
- the
show
方法也不会产生任何输出,表明所有行都消失了。
同样,当我将此脚本保存为 AWS Glue 控制台中的作业并运行它时,该作业不会指示发生任何错误 - 作业状态为“成功”。值得注意的是,我do得到print
声明和logging.error
调用输出到作业日志,但仅限于常规“日志”,而不是“错误日志”。
我想要的是能够表明我的工作失败了,并且能够轻松地找到这些错误日志。最重要的是仅仅表明它已经失败了。
有没有一种方法可以在映射函数中记录错误,以便 Glue 将其作为“错误日志”(并将其放入单独的 AWS CloudWatch Logs 路径中)?如果发生这种情况,它会自动将整个作业标记为失败吗?或者是否有其他方法可以从映射函数中显式地使作业失败?
(我的计划,如果有办法记录错误和/或将作业标记为失败,是创建一个装饰器或其他实用函数,它将自动捕获映射函数中的异常,并确保它们被记录并标记为失败)。