如何在AWS中分配动态资产ID站点监视仪表板定义云形式?
我们创建了一个云形式模板,用于自动实现AWS站点监视仪表板。我们想在下面的仪表板定义中动态地引用并分配资产逻辑ID。
{\"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\":[]}}]}
通过添加向后斜线()以及双引号,将此JSON的字面形式转换为YAML,因为我们将YAML用作CloudFormation模板的默认语言,否则看起来如下。
{
"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": []
}
}
]
}
我们想使用预先创建的资产动态分配资产ID。我们尝试了以下变化,但没有命运。
现有值 - > 0CD25CB9-89F9-4A93-B2BF-88050436F700
尝试以下更改: -
[{\"Ref\":\"GeneratorAsset\"}]
!Ref GeneratorAsset
\"!Ref GeneratorAsset\"
{\"Ref\":GeneratorAsset}
{\"Ref\":\"GeneratorAsset\"}
\"{\"Ref\":\"GeneratorAsset\"}\"
\"{\"Fn::Sub\":${GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset}}\"
\"{\"Fn::Sub\":${!GeneratorAsset} }\"
此处GeneratorAsaters是在仪表板之前已经创建的资源。请求任何云形式专家,以帮助我们用正确的动态字符串替换ID值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论