gpt4 book ai didi

aws-cloudformation - 警报仪表板的云信息模板

转载 作者:行者123 更新时间:2023-12-03 07:29:18 27 4
gpt4 key购买 nike

我已经为 CloudWatch 仪表板创建了 CloudFormation 模板,并且尝试使用 AlarmName 参数,但 Ref 值未传递,并且在下面的 AWS CloudFormation 中出现错误。

The field DashboardBody must be a valid JSON object (Service: AmazonCloudWatch; Status Code: 400; Error Code: InvalidParameterInput;
Request ID: e88b103e-8fba-42bc-b825-ed0e4bd6749a; Proxy: null)

模板:

AWSTemplateFormatVersion: 2010-09-09
Description: "AWS CloudFormation Sample Template for Cloudwatch alert and Dashboard configuration."
Parameters:
AlarmNameForCPU:
Default: Service_CpuUtilization
Description: AlarmName
MaxLength: "99"
MinLength: "1"
Type: String
AlarmNameForMemory:
Default: Service_MemoryUtilization
Description: AlarmName
MaxLength: "99"
MinLength: "1"
Type: String
DashboardName:
Default: ServiceDashboard
Description: Dashboard
MaxLength: "99"
MinLength: "1"
Type: String
DashboardTitleCPU:
Default: CpuUtilization
Description: DashboardTitle
MaxLength: "99"
MinLength: "1"
Type: String
DashboardTitleMemory:
Default: MemoryUtilization
Description: DashboardTitle
MaxLength: "99"
MinLength: "1"
Type: String
Resources:
Dashboard:
Type: "AWS::CloudWatch::Dashboard"
Properties:
DashboardName: !Ref DashboardName
DashboardBody: '{
"widgets":[
{
"height": 3,
"width": 9,
"y": 0,
"x": 0,
"type": "metric",
"properties": {
"title": "{"Ref DashboardTitleCPU"}",
"annotations": {
"alarms": [
"arn:aws:cloudwatch:us-east-1:468491150671:alarm: {"Ref" : "AlarmNameForCPU"}"
]
},
"view": "singleValue"
}
},
{
"height": 3,
"width": 9,
"y": 0,
"x": 9,
"type": "metric",
"properties": {
"title": "{"Ref DashboardTitleMemory"}",
"annotations": {
"alarms": [
"arn:aws:cloudwatch:us-east-1:468491150671:alarm: {"Ref AlarmNameForMemory"}"
]
},
"view": "singleValue"
}
}
]
}}}}]}'

最佳答案

您需要使用Sub function为此。

Resources:
Dashboard:
Type: "AWS::CloudWatch::Dashboard"
Properties:
DashboardName: !Ref DashboardName
DashboardBody: !Sub |
'{
"widgets":[
{
"height": 3,
"width": 9,
"y": 0,
"x": 0,
"type": "metric",
"properties": {
"title": "${DashboardTitleCPU}",
"annotations": {
"alarms": [
"arn:aws:cloudwatch:us-east-1:468491150671:alarm:${AlarmNameForCPU}"
]
},
"view": "singleValue"
}
},
{
"height": 3,
"width": 9,
"y": 0,
"x": 9,
"type": "metric",
"properties": {
"title": "${DashboardTitleMemory}",
"annotations": {
"alarms": [
"arn:aws:cloudwatch:us-east-1:468491150671:alarm:${AlarmNameForMemory}"
]
},
"view": "singleValue"
}
}
]
}'

关于aws-cloudformation - 警报仪表板的云信息模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68582429/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com