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

如何通过CloudFormation为CloudWatch仪表板指标设置持久时间范围

在CloudFormation中为CloudWatch仪表板小部件设置持久时间范围

要让CloudWatch仪表板的小部件独立于全局时间选择器、保持自定义时间范围,只需在目标小部件的properties配置中添加两项关键设置:

  • 开启持久时间范围:添加persistTime: true,对应控制台的「Persist time range」复选框功能
  • 指定自定义时间范围:通过period或timeRange定义小部件专属的时间范围(比如固定显示最近5分钟的数据)

修改后的完整CloudFormation代码

Resources:
  MyDashboard:
    Type: AWS::CloudWatch::Dashboard
    Properties:
      DashboardName: MyDashboard
      DashboardBody:
        Fn::ToJsonString:
          widgets:
            - type: metric
              x: 0
              y: 0
              width: 4
              height: 6
              properties:
                view: gauge
                # 开启持久时间范围,不受仪表板全局时间影响
                persistTime: true
                # 设置小部件固定显示最近5分钟的数据(300秒或"5m"均可)
                period: 300
                yAxis:
                  left:
                    min: 0
                    max: 100
                metrics:
                  -
                    - AWS/IoT
                    - MyThingsCount
                    - AggregationType
                    - count
                title: # of Things
                stat: Average
                region: !Ref AWS::Region
            - type: metric
              x: 4
              y: 0
              width: 6
              height: 6
              properties:
                metrics:
                  -
                    - AWS/IoT
                    - MyThingsCount
                    - AggregationType
                    - count
                title: Things over time
                stat: Average
                region: !Ref AWS::Region

关键说明

  • persistTime: true是核心开关,开启后小部件会忽略仪表板的全局时间设置,仅使用自身定义的时间范围
  • period用于指定指标数据的采样周期,同时会控制小部件的显示时间范围(如5m对应最近5分钟的数据)
  • 若需更灵活的时间范围(比如特定时间段),可替换为timeRange参数,示例:timeRange: {"start": "-1h", "end": "now"}

内容的提问来源于stack exchange,提问作者Gary Howe

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 22:23:27