本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用管理仪表板 AWS CLI
本节介绍了您可以运行的其他几个命令来管理仪表板,包括获取仪表板、列出仪表板、刷新仪表板和更新仪表板。
使用时 AWS CLI,请记住您的命令在 AWS 区域 配置文件中运行。如果您想要在不同的区域中运行命令,可以为配置文件更改默认区域,或者与命令一起使用 --region 参数。
使用以下命令获取仪表板 AWS CLI
运行get-dashboard命令返回仪表板。--dashboard-id通过提供控制面板 ARN 或控制面板名称来指定。
aws cloudtrail get-dashboard --dashboard-id arn:aws:cloudtrail:us-east-1:123456789012:dashboard/exampleDash
使用列出仪表板 AWS CLI
运行list-dashboards命令列出您账户的控制面板。
-
添加
--type参数,以仅查看CUSTOM或MANAGED控制面板。 -
包括
--max-results用于限制结果数量的参数。有效值为 1-100。 -
包括
--name-prefix返回与指定前缀匹配的仪表板。
以下示例列出了所有仪表板。
aws cloudtrail list-dashboards
此示例仅列出CUSTOM仪表板。
aws cloudtrail list-dashboards --type CUSTOM
下一个示例仅列出了MANAGED仪表板。
aws cloudtrail list-dashboards --type MANAGED
最后一个示例列出了与指定前缀匹配的仪表板。
aws cloudtrail list-dashboards --name-prefixExamplePrefix
将基于资源的策略附加到事件数据存储或仪表板 AWS CLI
运行put-resource-policy命令将基于资源的策略应用于事件数据存储或仪表板。
将基于资源的策略附加到事件数据存储
要在手动或计划刷新期间在仪表板上运行查询,您需要将基于资源的策略附加到与仪表板上的小组件关联的每个事件数据存储。这允许 CloudTrail Lake 代表您运行查询。有关基于资源的策略的更多信息,请参阅示例:允许 CloudTrail 运行查询以刷新仪表板。
以下示例将基于资源的策略附加到事件数据存储。account-id替换为您的账户 ID、eds-arn CloudTrail 将运行查询的事件数据存储的 ARN 以及控制面板dashboard-arn的 ARN。
aws cloudtrail put-resource-policy \ --resource-arneds-arn\ --resource-policy '{"Version": "2012-10-17", "Statement": [{"Sid": "EDSPolicy", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "cloudtrail:StartQuery", "Condition": { "StringEquals": { "AWS:SourceArn": "dashboard-arn", "AWS:SourceAccount": "account-id"}}} ]}'
将基于资源的策略附加到仪表板
要为仪表板设置刷新计划,您需要将基于资源的策略附加到仪表板,以允许 CloudTrail Lake 代表您刷新仪表板。有关基于资源的策略的更多信息,请参阅控制面板的基于资源的策略示例。
以下示例将基于资源的策略附加到仪表板。account-id替换为您的账户 ID dashboard-arn 和控制面板的 ARN。
aws cloudtrail put-resource-policy \ --resource-arndashboard-arn\ --resource-policy '{"Version": "2012-10-17", "Statement": [{"Sid": "DashboardPolicy", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": "cloudtrail:StartDashboardRefresh", "Condition": { "StringEquals": { "AWS:SourceArn": "dashboard-arn", "AWS:SourceAccount": "account-id"}}}]}'
使用手动刷新仪表板 AWS CLI
运行start-dashboard-refresh命令以手动刷新仪表板。在运行此命令之前,必须将基于资源的策略附加到与仪表板小组件关联的每个事件数据存储。
以下示例说明如何手动刷新自定义仪表板。
aws cloudtrail start-dashboard-refresh \ --dashboard-iddashboard-id\ --query-parameter-values '{"$StartTime$": "2024-11-05T10:45:24.00Z"}'
下一个示例说明如何手动刷新托管仪表板。由于托管仪表板是由配置的 CloudTrail,因此刷新请求需要包含将在其上运行查询的事件数据存储的 ID。
aws cloudtrail start-dashboard-refresh \ --dashboard-iddashboard-id\ --query-parameter-values '{"$StartTime$": "2024-11-05T10:45:24.00Z", "$EventDataStoreId$": "eds-id"}'
使用更新仪表板 AWS CLI
运行update-dashboard命令以更新仪表板。您可以更新仪表板以设置刷新计划、启用或禁用刷新计划、修改小组件以及启用或禁用终止保护。
使用更新刷新计划 AWS CLI
以下示例更新名为的自定义仪表板的刷新计划AccountActivityDashboard。
aws cloudtrail update-dashboard --dashboard-id AccountActivityDashboard \ --refresh-schedule '{"Frequency": {"Unit": "HOURS", "Value": 6}, "Status": "ENABLED"}'
使用自定义仪表板禁用终止保护和刷新计划 AWS CLI
以下示例禁用名为的自定义仪表板的终止保护AccountActivityDashboard,以允许删除该仪表板。它还会关闭刷新计划。
aws cloudtrail update-dashboard --dashboard-id AccountActivityDashboard \ --refresh-schedule '{ "Status": "DISABLED"}' \ --no-termination-protection-enabled
向自定义仪表板添加小部件
以下示例向名为的自定义仪表板添加了一个名TopServices为的新控件AccountActivityDashboard。widgets 数组包括已经为仪表板创建的两个小组件和新的微件。
注意
在此示例中,?用单引号括起来,因为它与一起使用eventTime。根据你运行的操作系统,你可能需要用转义引号将单引号括起来。有关更多信息,请参阅中的对字符串使用引号和文字。 AWS CLI
aws cloudtrail update-dashboard --dashboard-id AccountActivityDashboard \ --widgets '[ { "ViewProperties": { "Height": "2", "Width": "4", "Title": "TopErrors", "View": "Table" }, "QueryStatement": "SELECT errorCode, COUNT(*) AS eventCount FROM eds WHERE eventTime > '?' AND eventTime < '?' AND (errorCode is not null) GROUP BY errorCode ORDER BY eventCount DESC LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] }, { "ViewProperties": { "Height": "2", "Width": "4", "Title": "MostActiveRegions", "View": "PieChart", "LabelColumn": "awsRegion", "ValueColumn": "eventCount", "FilterColumn": "awsRegion" }, "QueryStatement": "SELECT awsRegion, COUNT(*) AS eventCount FROM eds where eventTime > '?' and eventTime < '?' GROUP BY awsRegion ORDER BY eventCount LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] }, { "ViewProperties": { "Height": "2", "Width": "4", "Title": "TopServices", "View": "BarChart", "LabelColumn": "service", "ValueColumn": "eventCount", "FilterColumn": "service", "Orientation": "Vertical" }, "QueryStatement": "SELECT replace(eventSource, '.amazonaws.com') AS service, COUNT(*) as eventCount FROM eds WHERE eventTime > '?' AND eventTime < '?' GROUP BY eventSource ORDER BY eventCount DESC LIMIT 100", "QueryParameters": ["$StartTime$", "$EndTime$"] } ]'