我的Cloudformation模板中有一个用于Lambda函数的Cloudwatch Dashboard小部件,例如
---
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而等效的AWS/States
被Invocations
发现all the options我可以用来代替FunctionName
,但是我不确定如何替换InstanceId
。 This建议我可以使用currentTimeMillis()
,但除此之外的文档数量有限。
如何为状态机创建AWS Cloudwatch仪表板小部件?
答案 0 :(得分:0)
我通过在AWS Web Console中创建小部件然后查看它生成的源来解决这个问题。以下对我有用。
"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
+ }
}
]
}'