【发布时间】:2020-06-23 20:05:24
【问题描述】:
我正在尝试使用云形成模板为状态机步进功能创建云手表仪表板。 由于错误“The field DashboardBody must be a valid JSON object”,堆栈创建失败。 知道如何传递取自模板参数部分的日志组名称吗?
下面是我的云形成模板:
AWSTemplateFormatVersion: 2010-09-09
Description: >-
CloudFormation template to create a dashboard for state functions
Parameters:
DashboardName:
Description: Name of the dashboard to create
Type: String
Default: Test-board
LambdaFunction:
Description: The Lambda function name.
Type: String
Default: test-lambda
StepFunction:
Description: The state function name.
Type: String
Default: MyStateMachine
Resources:
MetricsDashboard:
Type: 'AWS::CloudWatch::Dashboard'
Properties:
DashboardName: !Ref DashboardName
DashboardBody: !Join
- ''
- - >-
{ "widgets": [
{ "type": "log", "x": 6, "y": 6, "width": 18, "height": 3,
"properties": {
"query": "
- !Join
- ""
- "SOURCE '/aws/states/"
- ""
- !Ref StepFunction
- ""
- "' | fields @message\r\n| filter @message like /ERROR/| filter @message like /Exception/ "
- >-
",
"region": "eu-west-1", "stacked": false, "title": "{ Ref:StepFunction},
Step Function Error Logs", "view": "table" } },
{
"type": "metric",
"x": 0,
"y": 0,
"width": 5,
"height": 5,
"properties": {
"view": "singleValue",
"metrics": [
[ "AWS/States", "ExecutionsFailed", "StateMachineArn", "',{ Ref: StepFunction },'" ],
[ ".", "ExecutionsSucceeded", ".", ".", { "color": "#2ca02c" } ],
[ ".", "ExecutionsAborted", ".", ".", { "visible": false, "color": "#ff9896" } ]
],
"stat": "Sum",
"setPeriodToTimeRange": true,
"region": "', { Ref: AWS::Region }, '",
"title": "', "State-Function-", { Ref: StepFunction }," Counts", '",
"period": 300
}
}
]
}
提前致谢,
【问题讨论】:
-
创建仪表板通常最好在控制台中“可变”地进行,然后通过单击 UI 生成 CloudFormation
-
谢谢尼克拉斯。我试过了,它工作正常。但是我需要将日志组和步骤函数作为参数传递给更动态的仪表板。
-
尝试用
${StepFunction}替换{ Ref: StepFunction }等等。
标签: amazon-web-services amazon-cloudformation amazon-cloudwatch