带参数的 AWS Cloudformation 指标
AWS Cloudformation Metric With Parameters
我正在通过 Cloudformation 构建 Cloudwatch 仪表板。据我所知,您在构建指标时无法访问任何动态参数。这个对吗?除了硬编码引用之外,真的没有办法动态指定指标吗?我觉得这违背了云形成的目的。
也就是像下面这样动态选择区域:
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 20,
"height": 8,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
],
"title": "efficiency",
"region": "${AWS::Region}"
}
},
...
我已经尝试了任意数量的 combinations/methods 来引用 Cloudforamtion AWS::Region
参数。
这是真的吗?
您可以使用 Fn::Sub。例如:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: Dashboard1
DashboardBody: !Sub |
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 20,
"height": 8,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
],
"title": "efficiency",
"region": "${AWS::Region}"
}
}
]
当使用 JSON 模板时,通常在 Fn::Join 的结果上使用 Fn::Sub 以便于阅读格式。
我正在通过 Cloudformation 构建 Cloudwatch 仪表板。据我所知,您在构建指标时无法访问任何动态参数。这个对吗?除了硬编码引用之外,真的没有办法动态指定指标吗?我觉得这违背了云形成的目的。
也就是像下面这样动态选择区域:
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 20,
"height": 8,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
],
"title": "efficiency",
"region": "${AWS::Region}"
}
},
...
我已经尝试了任意数量的 combinations/methods 来引用 Cloudforamtion AWS::Region
参数。
这是真的吗?
您可以使用 Fn::Sub。例如:
MyDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: Dashboard1
DashboardBody: !Sub |
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 20,
"height": 8,
"properties": {
"view": "timeSeries",
"stacked": false,
"metrics": [
[ "LambdaFunc", "STATISTIC", { "stat": "Sum" } ]
],
"title": "efficiency",
"region": "${AWS::Region}"
}
}
]
当使用 JSON 模板时,通常在 Fn::Join 的结果上使用 Fn::Sub 以便于阅读格式。