模板验证错误:无效的模板资源属性。

问题描述 投票:0回答:1

我正在验证一个通过 Troposphere 脚本生成的 CloudFormation 模板。似乎导致错误的相关资源是一个公制转换,在 Troposphere 脚本中定义如下。

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文档. 为了提高可见度,这也是正在验证的模板中的度量转换资源的样子。

"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"
        }
amazon-web-services amazon-cloudformation troposphere
1个回答
0
投票

事实证明,MetricTransformation资源需要在MetricFilter本身中进行初始化,以便从Troposphere脚本生成正确的CloudFormation模板。如果您将MetricTransformation声明为一个单独的资源,并尝试在MetricFilter资源中引用它,那么接下来的模板将是错误的格式。

在Troposphere脚本中,正确的格式如下。

t.add_resource(logs.MetricFilter(
    "PlanReconciliationFiduciaryStepMetricFilter",
    FilterPattern="INFO generatePlanReconciliationStepKnownToFiduciary",
    LogGroupName=Ref("logGroupName"),
    MetricTransformations=[logs.MetricTransformation(
        "planReconciliationFiduciaryStepMetricTransformation",
        MetricNamespace=Ref("metricNamespace"),
        MetricName=Join("", [Ref("springProfile"), "-", "plan-reconciliation-fiduciary-step"]),
        MetricValue="1")]
))
© www.soinside.com 2019 - 2024. All rights reserved.