在Cloudwatch仪表板模板(Cloudformation)中使用伪变量 [英] Use Pseudo Variables in Cloudwatch Dashboard Template (Cloudformation)
问题描述
我正在尝试设置一个Cloud Formation模板来创建一个Cloudwatch-Dashboard。
在这种情况下,我想使用伪变量来确定区域。
I am trying to set up a Cloud Formation Template to create a Cloudwatch-Dashboard. In this context I want to use the Pseudo Variable to ascertain the Region.
如果我只是使用伪变量 AWS ::地区
代码似乎不起作用:
If I simply use the Pseudo Variable AWS::Region
the code doesnt seem to work:
AutoscalingDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: AutoscalingDashboard
DashboardBody: '
{
"widgets":[
{
"type":"metric",
"x":0,
"y":0,
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "invoice_web", "ClusterName", "InvoicegenappCluster" ],
[ "...", "invoice_data", ".", "." ],
[ "...", "invoice_generator", ".", "." ]
],
"region": "AWS::Region",
"period": 300,
"view": "timeSeries",
"title":"ECS MemoryUtilization",
"stacked": false
}
如何使用伪变量 AWS :: Region
或 Ref
函数动态地保留变量?
How can I use the Pseudo Variable AWS::Region
or a Ref
Function to keep the variables dynamically?
Merci A
推荐答案
在您的示例中, DashboardBody
是一个字符串,因此 AWS :: Region
不会被替换。
通过添加 Fn :: Sub
函数,例如:
In your example, the DashboardBody
is a string, therefore AWS::Region
will not get replaced.
You'll probably be better by adding the Fn::Sub
function, like:
AutoscalingDashboard:
Type: 'AWS::CloudWatch::Dashboard'
Properties:
DashboardName: 'AutoscalingDashboard'
DashboardBody: !Sub >-
{
"widgets":[
{
"type":"metric",
"x":0,
"y":0,
"width":12,
"height":6,
"properties":{
"metrics":[
[ "AWS/ECS", "MemoryUtilization", "ServiceName", "invoice_web", "ClusterName", "InvoicegenappCluster" ],
[ "...", "invoice_data", ".", "." ],
[ "...", "invoice_generator", ".", "." ]
],
"region": "${AWS::Region}",
"period": 300,
"view": "timeSeries",
"title":"ECS MemoryUtilization",
"stacked": false
}
}]
}
请注意该区域周围的 $ {}
以及YAML 阻止字符串>-
。
Notice the ${}
around the region, and also the YAML block string >-
.
这篇关于在Cloudwatch仪表板模板(Cloudformation)中使用伪变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!