AWS Glue:使用 pyspark 从脚本中获取 job_id

AWS Glue: get job_id from within the script using pyspark

我正在尝试从该作业的脚本访问 AWS ETL Glue 作业 ID。这是您可以在 AWS Glue 控制台的第一列中看到的 RunID,类似于 jr_5fc6d4ecf0248150067f2。如何使用 pyspark 以编程方式获取它?

您可以使用 boto3 SDK for python 访问 AWS 服务

import boto3

def lambda_handler(event, context):
    client = boto3.client('glue')
    client.start_crawler(Name='test_crawler')
    glue = boto3.client(service_name='glue', region_name='us-east-2',
              endpoint_url='https://glue.us-east-2.amazonaws.com')

    myNewJobRun = client.start_job_run(JobName=myJob['Name'])
    print myNewJobRun['JobRunId']

我没有在任何地方找到这个文档,但它作为命令行参数传入。

import sys
from awsglue.utils import getResolvedOptions

args = getResolvedOptions(sys.argv, ['JOB_NAME'])
job_run_id = args['JOB_RUN_ID']