You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API识别QuickSight仪表板的实际所有者?

批量获取QuickSight仪表板所有者的解决方案

调用describe-dashboard-permissions确实无法区分原所有者和被授予同等权限的共同所有者,因为两者的权限集合可能完全一致。要批量获取所有仪表板的所有者,更可靠的方式是使用list_dashboards API,该接口返回的每个仪表板摘要中包含CreatedBy字段,对应仪表板的创建者(默认即为所有者)。

实现代码

import boto3

def fetch_all_dashboard_owners(account_id, region="us-east-1"):
    quicksight = boto3.client("quicksight", region_name=region)
    owner_list = []
    
    # 分页遍历所有仪表板
    paginator = quicksight.get_paginator("list_dashboards")
    for page in paginator.paginate(AwsAccountId=account_id):
        for dashboard in page["DashboardSummaryList"]:
            creator = dashboard["CreatedBy"]
            owner_list.append({
                "仪表板ID": dashboard["DashboardId"],
                "仪表板名称": dashboard["Name"],
                "所有者ARN": creator["Arn"],
                "所有者用户名": creator["UserName"]
            })
    
    return owner_list

# 调用示例
if __name__ == "__main__":
    ACCOUNT_ID = "你的AWS账号ID"
    owners = fetch_all_dashboard_owners(ACCOUNT_ID)
    for item in owners:
        print(f"{item['仪表板名称']} ({item['仪表板ID']}) 的所有者: {item['所有者用户名']}")

特殊情况处理

如果存在手动转移仪表板所有权的场景,CreatedBy字段仍会保留原创建者信息,此时需要结合describe-dashboard-permissions接口验证当前实际所有者:

  1. 对每个仪表板调用describe-dashboard-permissions,获取权限列表
  2. 筛选出权限包含DASHBOARD_OWNER的主体(Principal)
  3. 若该主体与CreatedBy不一致,则为转移后的所有者

补充验证代码片段:

def get_current_dashboard_owner(account_id, dashboard_id, region="us-east-1"):
    quicksight = boto3.client("quicksight", region_name=region)
    response = quicksight.describe_dashboard_permissions(
        AwsAccountId=account_id,
        DashboardId=dashboard_id
    )
    # 筛选拥有DASHBOARD_OWNER权限的主体
    for perm in response["Permissions"]:
        if "DASHBOARD_OWNER" in perm["Actions"]:
            return perm["Principal"]
    return None

内容的提问来源于stack exchange,提问作者Lakshmi Sruthi K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:22:40