AwsGlueJobOperator配置WorkerType与NumberOfWorkers报错求助
尝试通过Airflow的AwsGlueJobOperator创建Glue任务,配置了NumberOfWorkers: 2和WorkerType: G.1X,但触发如下错误:
when calling the CreateJob operation:
Please do not set Allocated Capacity if using Worker Type and Number of Workers
使用的代码示例:
job_name = "glue_job" submit_glue_job = AwsGlueJobOperator( task_id="glue_job", job_name=job_name, wait_for_completion=True, # num_of_dpus=10, retry_limit=0, script_location=f"s3://bucket/etl.py", s3_bucket=GLUE_EXAMPLE_S3_BUCKET, iam_role_name=GLUE_CRAWLER_ROLE.split("/")[-1], create_job_kwargs={ 'GlueVersion': '3.0', 'NumberOfWorkers': 2, 'WorkerType': 'G.1X', "DefaultArguments": {"--enable-glue-datacatalog": ''} } )
解决方案
方案1:显式覆盖AllocatedCapacity参数
在create_job_kwargs中添加'AllocatedCapacity': 0,强制Glue使用Worker模式而非传统DPU分配模式:
job_name = "glue_job" submit_glue_job = AwsGlueJobOperator( task_id="glue_job", job_name=job_name, wait_for_completion=True, # num_of_dpus=10, retry_limit=0, script_location=f"s3://bucket/etl.py", s3_bucket=GLUE_EXAMPLE_S3_BUCKET, iam_role_name=GLUE_CRAWLER_ROLE.split("/")[-1], create_job_kwargs={ 'GlueVersion': '3.0', 'NumberOfWorkers': 2, 'WorkerType': 'G.1X', 'AllocatedCapacity': 0, # 新增此行覆盖默认值 "DefaultArguments": {"--enable-glue-datacatalog": ''} } )
方案2:升级Airflow Amazon Providers版本
你使用的3.2.0版本AwsGlueJobOperator存在默认传递allocated_capacity的问题,后续版本(如>=4.0.0)已修复该逻辑,不再默认设置该参数。升级后可直接使用原有配置,无需额外修改。
原因说明
在Airflow Amazon Providers 3.2.0的AwsGlueJobOperator实现中,即使未显式设置num_of_dpus,底层逻辑仍会默认传递allocated_capacity参数给Glue的CreateJob API。而AWS Glue明确禁止同时使用Worker模式参数(WorkerType/NumberOfWorkers)和传统的AllocatedCapacity参数,因此触发报错。显式设置AllocatedCapacity: 0可告知Glue忽略传统分配模式,启用Worker模式。
内容的提问来源于stack exchange,提问作者Sai Ganesh Kumbar

