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

使用Python编写的Lambda触发AWS Glue作业无响应如何排查?

排查及解决思路

1. 优先检查Lambda执行超时配置

  • Lambda默认执行超时时间为3秒,boto3调用Glue API冷启动、网络延迟时很容易超过该阈值,进程被强制终止就会出现仅打印启动日志、无后续输出也无报错的现象
  • 调整方案:将Lambda超时时间修改为至少10秒,最高可设置为15分钟

2. 排查Lambda网络配置问题

如果你的Lambda配置了VPC接入,需要满足以下任一条件,否则会出现Glue API调用卡住超时的情况:

  • Lambda所在VPC子网配置了NAT网关,具备公网访问能力,可正常调用公网Glue API
  • 为VPC添加Glue服务的VPC端点(VPCE),实现内网访问Glue API
    如果Lambda无需接入VPC,可直接删除VPC配置,使用默认AWS托管网络即可正常调用Glue API

3. 修正IAM权限配置

注意你提到的AWSGlueServiceRole是Glue作业自身运行时使用的角色,不是Lambda触发Glue需要的权限,你需要为Lambda的执行角色单独添加以下权限策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "glue:StartJobRun",
            "Resource": "arn:aws:glue:<你的区域>:<你的账号ID>:job/<你的Glue作业名称>"
        }
    ]
}

4. 为boto3客户端添加超时配置,便于定位问题

修改Lambda代码,给Glue客户端添加显式超时配置,避免调用无限卡住,触发明确报错方便排查:

import boto3
from botocore.exceptions import ClientError
from botocore.config import Config

def handler(event, context):
   # 配置客户端超时时间:连接超时5秒,读取超时10秒
   config = Config(connect_timeout=5, read_timeout=10)
   glue_client = boto3.client('glue', config=config, region_name='<你的Glue作业所在区域>')
   job_name = 'my-glue-job-name'
   
   try:
      print('Attempting to start glue job:', job_name)
      job_run_response = glue_client.start_job_run(JobName=job_name)
      job_run_id = job_run_response['JobRunId']
      print('Running Glue job, id:', job_run_id)
      return job_run_id
   except ClientError as e:
      print('>>>>>>error 1:', e)
      raise Exception( "boto3 client error in run_glue_job: " + e.__str__())
   except Exception as e:
      print('>>>>>>error 2:', e)
      raise Exception( "Unexpected error in run_glue_job: " + e.__str__())

注意原有代码直接取glue_client.start_job_run的返回值是完整响应对象,需要取JobRunId字段才能获得作业运行ID

5. 确认基础配置匹配

  • 确认Glue作业名称完全匹配,无大小写、拼写错误
  • 确认Lambda所在区域和Glue作业所在区域一致,若不一致需要在初始化Glue客户端时显式指定region_name参数

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 19:24:03