Amazon cloudformation 在Cloudwatch仪表板模板中使用伪变量(Cloudformation)

Amazon cloudformation 在Cloudwatch仪表板模板中使用伪变量(Cloudformation),amazon-cloudformation,Amazon Cloudformation,我正在尝试设置一个云形成模板来创建Cloudwatch仪表板。 在本文中,我想使用伪变量来确定区域 如果我只是使用伪变量AWS::Region,代码似乎不起作用: AutoscalingDashboard: Type: AWS::CloudWatch::Dashboard Properties: DashboardName: AutoscalingDashboard DashboardBody: ' { "widgets":[ {

我正在尝试设置一个云形成模板来创建Cloudwatch仪表板。 在本文中,我想使用伪变量来确定区域

如果我只是使用伪变量
AWS::Region
,代码似乎不起作用:

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
函数动态保存变量


Merci A

在您的示例中,
仪表板主体是一个字符串,因此不会替换
AWS::Region
。 添加函数可能会更好,如:

自动缩放仪表板:
类型:“AWS::CloudWatch::Dashboard”
特性:
仪表板名称:“自动缩放仪表板”
仪表板主体:!Sub>-
{
“小部件”:[
{
“类型”:“公制”,
“x”:0,
“y”:0,
“宽度”:12,
“高度”:6,
“财产”:{
“指标”:[
[“AWS/ECS”、“MemoryUtilization”、“ServiceName”、“invoice_web”、“ClusterName”、“InvoicegenappCluster”],
[“…”,“发票数据”,“,”,
[“…”、“发票生成器”、“、”]
],
“区域”:“${AWS::region}”,
“期间”:300,
“视图”:“timeSeries”,
“标题”:“ECS内存使用”,
“堆叠”:错误
}           
}]
}
注意区域周围的
${}
,以及YAML