1

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.

If I simply use the Pseudo Variable AWS::Regionthe 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
            }

How can I use the Pseudo Variable AWS::Region or a RefFunction to keep the variables dynamically?

Merci A

aerioeus
  • 1,348
  • 1
  • 16
  • 41

1 Answers1

1

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

Notice the ${} around the region, and also the YAML block string >-.

tyron
  • 3,715
  • 1
  • 22
  • 36