简体   繁体   中英

AWS Cloudformation Metric With Parameters

I am building Cloudwatch dashboards via Cloudformation. As far as I can tell, you cannot access any dynamic parameters while building metrics. Is this correct? Is there truly no way to dynamically specify metrics other than to hard code references? I feel like this defeats the purpose of cloudformation.

AKA something like the below to dynamically choose the region:

"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}"
        }
    },
...

I have tried any number of combinations/methods to reference the Cloudforamtion AWS::Region parameter.

Is this really it?

You can use Fn::Sub for that. For example:

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}"
          }
        }
      ]

When using JSON templates, you usually use Fn::Sub on the result of Fn::Join for easier to read formatting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM