Amazon web services 模板验证错误:无效的模板资源属性

Amazon web services 模板验证错误:无效的模板资源属性,amazon-web-services,amazon-cloudformation,troposphere,Amazon Web Services,Amazon Cloudformation,Troposphere,我正在验证通过对流层脚本生成的云形成模板。引起错误的相关资源是一个度量转换,在对流层脚本中定义如下: t.add_resource(logs.MetricTransformation( "planReconciliationFiduciaryStepMetricTransformation", MetricNamespace=Ref("metricNamespace"), MetricName=Join("", [Ref("springProfile"), "-", "p

我正在验证通过对流层脚本生成的云形成模板。引起错误的相关资源是一个度量转换,在对流层脚本中定义如下:

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属性似乎从中得到了很好的定义。对于可见性,这也是正在验证的模板中的度量转换资源的外观:

"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"
        }

事实证明,MetricTransformation资源需要在MetricFilter本身内初始化,以便从对流层脚本生成正确的云形成模板。如果将MetricTransformation声明为单独的资源,并尝试在MetricFilter资源中引用它,则后续模板的格式将不正确

对流层脚本中的正确格式如下所示:

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")]
))

你能提供完整的
MetricFilter
生成的模板吗?@Marcin是的,已更新这似乎很好。您确定问题出在这个特定的
MetricName
上吗?也许在你的模板中,你在其他资源中有一些其他的
MetricName
?我想我发现了问题和解决方法。MetricTransformation需要在MetricFilter本身中定义,而不是在外部定义并作为引用传入。我将很快对此问题添加一个答案。