【发布时间】:2020-06-05 13:53:23
【问题描述】:
我正在验证通过对流层脚本生成的 CloudFormation 模板。似乎导致错误的有问题的资源是度量转换,在对流层脚本中定义如下:
t.add_resource(logs.MetricTransformation(
"planReconciliationFiduciaryStepMetricTransformation",
MetricNamespace=Ref("metricNamespace"),
MetricName=Join("", [Ref("springProfile"), "-", "plan-reconciliation-step-known-to-fiduciary"]),
MetricValue="1"
))
它所依赖的参数在脚本中预先定义如下:
t.add_parameter(Parameter(
"metricNamespace",
Type="String",
Default="BATCH-ERRORS",
Description="Metric namespace for CloudWatch filters"
))
t.add_parameter(Parameter(
"springProfile",
Type="String",
Default=" ",
Description="SPRING PROFILE"
))
我正在运行的确切命令是
aws cloudformation validate-template --template-body
file://hor-ubshobackgroundtaskdefinition.template --profile saml
结果输出
An error occurred (ValidationError) when calling the ValidateTemplate operation:
Invalid template resource property 'MetricName'
我的 MetricTransformation 属性似乎在 AWS documentation 中得到了很好的定义。为了可见性,这也是模板中正在验证的指标转换资源的样子:
"planReconciliationFiduciaryStepMetricTransformation": {
"MetricName": {
"Fn::Join": [
"",
[
{
"Ref": "springProfile"
},
"-",
"plan-reconciliation-step-known-to-fiduciary"
]
]
},
"MetricNamespace": {
"Ref": "metricNamespace"
},
"MetricValue": "1"
}
有什么想法吗?
更新:
根据要求,添加指标过滤器资源:
"PlanReconciliationFiduciaryStepMetricFilter": {
"Properties": {
"FilterPattern": "INFO generatePlanReconciliationStepKnownToFiduciary",
"LogGroupName": {
"Ref": "logGroupName"
},
"MetricTransformations": [
{
"Ref": "planReconciliationFiduciaryStepMetricTransformation"
}
]
},
"Type": "AWS::Logs::MetricFilter"
}
【问题讨论】:
-
你能提供完整的
MetricFilter生成的模板吗? -
@Marcin 是的,已更新
-
这看起来不错。您确定问题出在这个特定的
MetricName上吗?也许在您的模板中,您在其他资源中还有其他MetricName? -
我想我发现了问题并解决了。 MetricTransformation 需要在 MetricFilter 本身内定义,而不是在外部定义并作为引用传入。我很快就会对此效果添加答案。
标签: amazon-web-services amazon-cloudformation troposphere