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

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

ภาพรวม

สาธิตการดึงรายการ schema ทั้งหมดใน AWS Glue Schema Registry โดยใช้ list_schemas

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

import boto3
from botocore.exceptions import ClientError

def list_schemas():
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.list_schemas()
        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_schemas())

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

{
    'Schemas': [
        {
            'RegistryName': 'employee_details',
            'SchemaName': 'employee_table',
            'SchemaArn': 'string',
            'Description': 'Schema for employees record',
            'Status': 'AVAILABLE',
            'CreatedTime': 'string',
            'UpdatedTime': 'string'
        },
        {
            'RegistryName': 'security_details',
            'SchemaName': 'security_table',
            'SchemaArn': 'string',
            'Description': 'Schema for security record',
            'Status': 'AVAILABLE',
            'CreatedTime': 'string',
            'UpdatedTime': 'string'
        }
    ],
    'NextToken': '...'
}

คำอธิบาย

  • ส่งคืน schema ที่มีสถานะ AVAILABLE เท่านั้น (ไม่รวม DELETING)
  • ข้อมูลเป็น limited details ต้องใช้ get_schema เพื่อดูรายละเอียดเต็ม
  • รองรับ pagination ด้วย NextToken
  • ต้องมี permission glue:ListSchemas