You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Glue Transform调用get_job_run报错:GlueContext无该属性,求解决思路

Glue自定义代码AttributeError错误解决思路

问题背景

  • 触发链路:S3上传CSV文件触发Lambda,Lambda调用Glue Job
  • 错误场景:Glue Job的「Transform-自定义代码」节点第2行报错
  • 出错代码:
def MyTransform (glueContext, dfc) -> DynamicFrameCollection:
    rules_file_path = glueContext.get_job_run().get_job_argument("--rules-file-path")
  • 错误信息:AttributeError: 'GlueContext' object has no attribute 'get_job_run'

解决步骤

  • 问题根源:get_job_run()不属于GlueContext的方法,无法直接通过GlueContext实例调用该方法获取作业参数。
  • 正确获取作业参数的方式:
    • 使用GlueContext提供的get_resolved_options()方法,这是官方推荐的获取作业命令行参数的方式,示例代码:
      import sys
      def MyTransform (glueContext, dfc) -> DynamicFrameCollection:
          # 传入需要获取的参数名(无需带--前缀)
          args = glueContext.get_resolved_options(sys.argv, ['rules-file-path'])
          rules_file_path = args['rules-file-path']
          # 此处编写你的数据转换逻辑
          return dfc
      
    • 配置校验:确保Glue Job运行时已经正确配置了--rules-file-path命令行参数,否则会触发参数未找到的异常。

内容的提问来源于stack exchange,提问作者ScotterMonkey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 23:58:10