AWS Cloudformation指标与参数

时间:2018-02-22 21:20:25

标签: amazon-web-services amazon-cloudformation amazon-cloudwatch

我正在通过Cloudformation构建Cloudwatch仪表板。据我所知,在构建指标时,您无法访问任何动态参数。它是否正确?真的没有办法动态指定除硬编码引用之外的指标吗?我觉得这会破坏cloudformation的目的。

AKA如下所示动态选择区域:

"widgets": [
    {
        "type": "metric",
        "x": 0,
        "y": 0,
        "width": 20,
        "height": 8,
        "properties": {
            "view": "timeSeries",
            "stacked": false,
            "metrics": [
                [ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
            ],
            "title": "efficiency",
            "region": "${AWS::Region}"
        }
    },
...

我尝试过任意数量的组合/方法来引用Cloudforamtion AWS::Region参数。

这是真的吗?

1 个答案:

答案 0 :(得分:1)

您可以使用Fn::Sub。例如:

MyDashboard:
  Type: AWS::CloudWatch::Dashboard
  Properties:
    DashboardName: Dashboard1
    DashboardBody: !Sub |
      "widgets": [
        {
          "type": "metric",
          "x": 0,
          "y": 0,
          "width": 20,
          "height": 8,
          "properties": {
            "view": "timeSeries",
            "stacked": false,
            "metrics": [
              [ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
            ],
            "title": "efficiency",
            "region": "${AWS::Region}"
          }
        }
      ]

使用JSON模板时,通常在Fn::Join的结果上使用Fn :: Sub,以便于阅读格式。