您如何在 Cloudwatch 仪表板小部件模板中引用特定的 AWS::StateMachine?
How do you reference a particular AWS::StateMachine in Cloudwatch Dashboard widget Template?
我的 Cloudformation 模板中有一个用于 Lambda 函数的 Cloudwatch 仪表板小部件,例如,
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyLambda:
Type: AWS::Serverless::Function
...
MyStateMachine:
Type: "AWS::StepFunctions::StateMachine"
...
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: MyDashboard
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 3,
"width": 24,
"height": 3,
"properties": {
"view": "singleValue",
"metrics": [
[ "AWS/Lambda", "Invocations", "FunctionName", "${MyLambda}", { "stat": "Sum", "period": 86400 } ],
[ ".", "Duration", ".", ".", { "stat": "Average", "period": 86400, "color": "#2ca02c" } ],
[ ".", "Errors", ".", ".", { "stat": "Sum", "period": 86400, "color": "#d62728" } ],
[ ".", "Throttles", ".", ".", { "stat": "Sum", "period": 86400, "color": "#ff7f0e" } ]
],
"region": "us-west-2",
"title": "MyLambda",
"stacked": true
}
}
]
}'
我想将 MyStateMachine
的小部件添加到此仪表板,但我不知道如何编写状态机等效于,
[ "AWS/Lambda", "Invocations", "FunctionName", "${MyLambda}", { "stat": "Sum", "period": 86400 } ]
我发现 AWS/Lambda
被调用并且 AWS Namespace and the equivalent one is AWS/States
and I found all the options I can use in place of Invocations
, but I am not sure how to replace FunctionName
. This 建议我可以使用 InstanceId
,但除此之外的文档有限。
如何为我的状态机创建 AWS Cloudwatch 仪表板小部件?
我通过在 AWS Web 控制台中创建小部件然后查看它生成的源代码来解决这个问题。以下对我有用。
"title": "MyLambda",
"stacked": true
}
+ },
+ {
+ "type": "metric",
+ "x": 0,
+ "y": 9,
+ "width": 24,
+ "height": 3,
+ "properties": {
+ "view": "timeSeries",
+ "metrics": [
+ [ "AWS/States", "ActivitiesStarted", "ActivityArn", "${MyStateMachine}", { "stat": "Sum", "period": 86400 } ]
+ ],
+ "region": "us-west-2",
+ "title": "State Machine Metrics",
+ "period": 300
+ }
}
]
}'
我的 Cloudformation 模板中有一个用于 Lambda 函数的 Cloudwatch 仪表板小部件,例如,
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyLambda:
Type: AWS::Serverless::Function
...
MyStateMachine:
Type: "AWS::StepFunctions::StateMachine"
...
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: MyDashboard
DashboardBody:
Fn::Sub: '{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 3,
"width": 24,
"height": 3,
"properties": {
"view": "singleValue",
"metrics": [
[ "AWS/Lambda", "Invocations", "FunctionName", "${MyLambda}", { "stat": "Sum", "period": 86400 } ],
[ ".", "Duration", ".", ".", { "stat": "Average", "period": 86400, "color": "#2ca02c" } ],
[ ".", "Errors", ".", ".", { "stat": "Sum", "period": 86400, "color": "#d62728" } ],
[ ".", "Throttles", ".", ".", { "stat": "Sum", "period": 86400, "color": "#ff7f0e" } ]
],
"region": "us-west-2",
"title": "MyLambda",
"stacked": true
}
}
]
}'
我想将 MyStateMachine
的小部件添加到此仪表板,但我不知道如何编写状态机等效于,
[ "AWS/Lambda", "Invocations", "FunctionName", "${MyLambda}", { "stat": "Sum", "period": 86400 } ]
我发现 AWS/Lambda
被调用并且 AWS Namespace and the equivalent one is AWS/States
and I found all the options I can use in place of Invocations
, but I am not sure how to replace FunctionName
. This 建议我可以使用 InstanceId
,但除此之外的文档有限。
如何为我的状态机创建 AWS Cloudwatch 仪表板小部件?
我通过在 AWS Web 控制台中创建小部件然后查看它生成的源代码来解决这个问题。以下对我有用。
"title": "MyLambda",
"stacked": true
}
+ },
+ {
+ "type": "metric",
+ "x": 0,
+ "y": 9,
+ "width": 24,
+ "height": 3,
+ "properties": {
+ "view": "timeSeries",
+ "metrics": [
+ [ "AWS/States", "ActivitiesStarted", "ActivityArn", "${MyStateMachine}", { "stat": "Sum", "period": 86400 } ]
+ ],
+ "region": "us-west-2",
+ "title": "State Machine Metrics",
+ "period": 300
+ }
}
]
}'