How to allocate dynamic Asset Id in Aws Sitewise monitoring dashboard definition Cloudformation?

199 Views Asked by At

We created a Cloudformation template for auto implementation of the AWS Sitewise monitoring dashboard. We would like to dynamically refer and assign the Asset logical id inside the below dashboard definition.

{\"widgets\":[{\"type\":\"sc-line-chart\",\"title\":\"power_all_plants_5m\",\"x\":0,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"power_all_plants_5m (All Power Plants)\",\"assetId\":\"0cd25cb9-89f9-4a93-b2bf-88050436f700\",\"propertyId\":\"fd34bba7-4ea2-4d62-9058-ab78b726b61a\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-1\",\"x\":3,\"y\":0,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-1)\",\"assetId\":\"45b97aaa-3f0c-4312-a8a5-a00e4da8ec37\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}},{\"type\":\"sc-line-chart\",\"title\":\"Generator-2\",\"x\":0,\"y\":3,\"height\":3,\"width\":3,\"metrics\":[{\"type\":\"iotsitewise\",\"label\":\"sum_watts_5m (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"e22d9a23-4ac8-432a-816b-cc4a2138b287\",\"dataType\":\"DOUBLE\"},{\"type\":\"iotsitewise\",\"label\":\"rpm (Generator-2)\",\"assetId\":\"b999319c-20ec-4060-b3b7-bc5ce7ef189c\",\"propertyId\":\"c6a40902-f07b-40ba-b6c5-3509b069dd4c\",\"dataType\":\"DOUBLE\"}],\"alarms\":[],\"properties\":{\"colorDataAcrossThresholds\":true},\"annotations\":{\"y\":[]}}]}

This JSON literal is converted to YAML by adding backward slashes () along with the double quotes because we are using YAML as the default language of the Cloudformation template otherwise it looks like the below.

{
  "widgets": [
    {
      "type": "sc-line-chart",
      "title": "power_all_plants_5m",
      "x": 0,
      "y": 0,
      "height": 3,
      "width": 3,
      "metrics": [
        {
          "type": "iotsitewise",
          "label": "power_all_plants_5m (All Power Plants)",
          "assetId": "0cd25cb9-89f9-4a93-b2bf-88050436f700",
          "propertyId": "fd34bba7-4ea2-4d62-9058-ab78b726b61a",
          "dataType": "DOUBLE"
        }
      ],
      "alarms": [],
      "properties": {
        "colorDataAcrossThresholds": true
      },
      "annotations": {
        "y": []
      }
    },
    {
      "type": "sc-line-chart",
      "title": "Generator-1",
      "x": 3,
      "y": 0,
      "height": 3,
      "width": 3,
      "metrics": [
        {
          "type": "iotsitewise",
          "label": "sum_watts_5m (Generator-1)",
          "assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
          "propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
          "dataType": "DOUBLE"
        },
        {
          "type": "iotsitewise",
          "label": "rpm (Generator-1)",
          "assetId": "45b97aaa-3f0c-4312-a8a5-a00e4da8ec37",
          "propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
          "dataType": "DOUBLE"
        }
      ],
      "alarms": [],
      "properties": {
        "colorDataAcrossThresholds": true
      },
      "annotations": {
        "y": []
      }
    },
    {
      "type": "sc-line-chart",
      "title": "Generator-2",
      "x": 0,
      "y": 3,
      "height": 3,
      "width": 3,
      "metrics": [
        {
          "type": "iotsitewise",
          "label": "sum_watts_5m (Generator-2)",
          "assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
          "propertyId": "e22d9a23-4ac8-432a-816b-cc4a2138b287",
          "dataType": "DOUBLE"
        },
        {
          "type": "iotsitewise",
          "label": "rpm (Generator-2)",
          "assetId": "b999319c-20ec-4060-b3b7-bc5ce7ef189c",
          "propertyId": "c6a40902-f07b-40ba-b6c5-3509b069dd4c",
          "dataType": "DOUBLE"
        }
      ],
      "alarms": [],
      "properties": {
        "colorDataAcrossThresholds": true
      },
      "annotations": {
        "y": []
      }
    }
  ]
}

We would like to assign Asset ID dynamically using "!Ref" with pre-created Asset. We have tried the below variations but no fate.

Existing value -> 0cd25cb9-89f9-4a93-b2bf-88050436f700

Tried below changes:-

[{\"Ref\":\"GeneratorAsset\"}]
!Ref GeneratorAsset
\"!Ref GeneratorAsset\"
{\"Ref\":GeneratorAsset}
{\"Ref\":\"GeneratorAsset\"}
\"{\"Ref\":\"GeneratorAsset\"}\"
\"{\"Fn::Sub\":${GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset} }\"

Here GeneratorAsset is a resource that is already created before Dashboard. Request any Cloudformation expert to help us replace the id value with the correct dynamic string.

Ref link:- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iotsitewise-dashboard.html

0

There are 0 best solutions below