【问题标题】:Template validation error: invalid template resource property模板验证错误:无效的模板资源属性
【发布时间】: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


【解决方案1】:

事实证明,需要在 MetricFilter 本身内初始化 MetricTransformation 资源,以便从对流层脚本生成正确的 CloudFormation 模板。如果您将 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")]
))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 2018-12-15
    • 2020-10-21
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    相关资源
    最近更新 更多