Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ดึงรายละเอียด Triggers ทั้งหมดที่เชื่อมโยงกับ Job จาก AWS Glue Data Catalog ด้วย Boto3

ใช้ Boto3 ดึง Triggers ที่เกี่ยวข้องกับ Job เฉพาะใน AWS Glue Data Catalog

ตัวอย่าง

ดึง Triggers ที่เชื่อมโยงกับ Job ชื่อ employee_details

ขั้นตอน/อัลกอริทึม

  1. Import boto3 และ botocore.exceptions.ClientError
  2. job_name เป็นพารามิเตอร์ทางเลือก (ถ้าไม่ระบุ จะดึง Triggers ทั้งหมด)
  3. สร้าง AWS Session และ Glue Client
  4. เรียก get_triggers(DependentJobName=job_name)
  5. คืนค่ารายการ Triggers
  6. จัดการ Exception

ตัวอย่างโค้ด

import boto3
from botocore.exceptions import ClientError

def get_details_of_triggers(job_name=None):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_triggers(DependentJobName=job_name)
        return response
    except ClientError as e:
        raise Exception("boto3 client error in get_details_of_triggers: " + e.__str__())
    except Exception as e:
        raise Exception("Unexpected error in get_details_of_triggers: " + e.__str__())

a = get_details_of_triggers('employee_details')
print(a)

ผลลัพธ์

{'Triggers': [{'Name': '01_PythonShellTest1', 'WorkflowName': 'arn:aws:iam::1234:role/dev-edl', 'Id': 'string', 'Type': 'SCHEDULED'|'CONDITIONAL'|'ON_DEMAND', 'State': 'CREATING'|'CREATED'|'ACTIVATING'|'ACTIVATED'|'DEACTIVATING'|'DEACTIVATED'|'DELETING'|'UPDATING', 'Description': 'string', 'Schedule': 'string'}]}