AWS CloudWatch仪表板CloudFormation配置

时间:2017-09-29 11:42:01

标签: amazon-web-services amazon-cloudformation

我正在尝试使用基本小部件来配置仪表板以公开CpUUtilization指标。 我无法引用之前创建的EC2实例,因为似乎在描述仪表板的json中没有解释!Ref函数。

metrics": [
        "AWS/EC2",
        "CPUUtilization",
        "InstanceId",
        "!Ref Ec2Instance"
]

知道如何按逻辑名称引用它吗?

1 个答案:

答案 0 :(得分:5)

您可以使用Fn::Join将内部函数(如Ref)的输出与字符串组合在一起。例如:

  CloudWatchDashboardHOSTNAME:
    Type: "AWS::CloudWatch::Dashboard"
    DependsOn: Ec2InstanceHOSTNAME
    Properties:
      DashboardName: HOSTNAME
      DashboardBody: { "Fn::Join": [ "", ['{"widgets":[
          {
            "type":"metric",
            "properties":{
              "metrics":[
                ["AWS/EC2","CPUUtilization","InstanceId",
                 "', { Ref: Ec2InstanceHOSTNAME }, '"] 
              ],
              "title":"CPU Utilization",
              "period":60,
              "region":"us-east-1"
            }
          }]}' ] ] } 

文档: