gpt4 book ai didi

amazon-web-services - 模板验证错误: invalid template resource property

转载 作者:行者123 更新时间:2023-12-03 07:35:18 24 4
gpt4 key购买 nike

我正在验证通过对流层脚本生成的 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"
}

最佳答案

事实证明,MetricTransformation 资源需要在 MetricFilter 本身内进行初始化,以便从 Troposphere 脚本生成正确的 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")]
))

关于amazon-web-services - 模板验证错误: invalid template resource property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62203760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com