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

ใช้ Boto3 ดึงรายการ Triggers ทั้งหมดใน AWS Account

ภาพรวม

สาธิตการดึงรายชื่อ trigger ทั้งหมดใน AWS Glue Data Catalog โดยใช้ list_triggers

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

import boto3
from botocore.exceptions import ClientError

def list_triggers():
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.list_triggers()
        return response
    except ClientError as e:
        raise Exception(f"boto3 client error: {e}")
    except Exception as e:
        raise Exception(f"Unexpected error: {e}")

# ใช้งาน
print(list_triggers())

ผลลัพธ์ตัวอย่าง

{
    'TriggerNames': [
        'data-etl-file-passed-to-splitter',
        'file-passed-to-worker',
        'file-trigger',
        'test-daily-jobs',
        'test-daily-jobs-copy'
    ],
    'ResponseMetadata': {
        'RequestId': '8e95115b-...',
        'HTTPStatusCode': 200,
        ...
    }
}

คำอธิบาย

  • ส่งคืน list ของ trigger names
  • รองรับพารามิเตอร์ Tags เพื่อกรอง trigger ที่มี tag เฉพาะ
  • รองรับ pagination ด้วย MaxResults และ NextToken
  • ต้องมี permission glue:ListTriggers