我正在尝试使用基本小部件来配置仪表板以公开CpUUtilization指标。 我无法引用之前创建的EC2实例,因为似乎在描述仪表板的json中没有解释!Ref函数。
metrics": [
"AWS/EC2",
"CPUUtilization",
"InstanceId",
"!Ref Ec2Instance"
]
知道如何按逻辑名称引用它吗?
答案 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"
}
}]}' ] ] }
文档: