如何解决“为不需要模板的模板指定了参数值”尝试通过AWS cloudformation部署一致性包时
我正在研究通过AWS cloudformation部署一致性包的概念证明,并且为错误“为不需要模板的模板指定了参数值”而感到困惑。我正在使用的配置规则确实需要一个参数。附带代码。我还使用cfn-lint测试了该模板,并且未收到任何反馈/错误。
我的模板是“简单”及以下版本:
Parameters:
ElbPredefinedSecurityPolicySslCheckParamPredefinedPolicyName:
Default: ELBSecurityPolicy-2016-08
Type: String
Resources:
TestingConformancePack:
Type: AWS::Config::ConformancePack
Properties:
ConformancePackName: TestCP
ConformancePackInputParameters:
-
ParameterName: PredefinedPolicyName
ParameterValue: !Ref ElbPredefinedSecurityPolicySslCheckParamPredefinedPolicyName
TemplateBody: |
Resources:
ElbPredefinedSecurityPolicySslCheck:
Properties:
ConfigRuleName: elb-predefined-security-policy-ssl-check
InputParameters:
predefinedPolicyName:
Ref: ElbPredefinedSecurityPolicySslCheckParamPredefinedPolicyName
Scope:
ComplianceResourceTypes:
- AWS::ElasticLoadBalancing::LoadBalancer
Source:
Owner: AWS
SourceIdentifier: ELB_PredefineD_Security_POLICY_SSL_CHECK
Type: AWS::Config::ConfigRule
解决方法
原因是您将参数(ConformancePackInputParameters
中指定的参数)传递给不包含TemplateBody
部分的CloudFormation模板(Parameters
中指定的参数),并且因此,不需要任何参数。要解决此问题,您需要向内部CloudFormation模板添加参数,然后可以在predefinedPolicyName
中引用该参数:
以下模板对我有用:
Parameters:
ElbPredefinedSecurityPolicySslCheckParamPredefinedPolicyName:
Default: ELBSecurityPolicy-2016-08
Type: String
Resources:
TestingConformancePack:
Type: AWS::Config::ConformancePack
Properties:
ConformancePackName: TestCP
ConformancePackInputParameters:
-
ParameterName: PredefinedPolicyName
ParameterValue: !Ref ElbPredefinedSecurityPolicySslCheckParamPredefinedPolicyName
TemplateBody: |
Parameters:
PredefinedPolicyName:
Type: String
Resources:
ElbPredefinedSecurityPolicySslCheck:
Properties:
ConfigRuleName: elb-predefined-security-policy-ssl-check
InputParameters:
predefinedPolicyName:
Ref: PredefinedPolicyName
Scope:
ComplianceResourceTypes:
- AWS::ElasticLoadBalancing::LoadBalancer
Source:
Owner: AWS
SourceIdentifier: ELB_PREDEFINED_SECURITY_POLICY_SSL_CHECK
Type: AWS::Config::ConfigRule
,
我在使用 cloudformation 制作测试用例资源时偶然发现了同样的错误。 “为不需要它们的模板指定的参数值。”
由于是测试用例,我根本没有使用任何参数。上面的答案有助于我理解它必须对参数做一些事情。即使您没有使用任何参数,在部署 cfn 时也会传递一些参数。
默认情况下,cloudformation 还将 env 作为参数发送,该参数需要在参数下。 (下面是 JSON 中的代码片段)
"Parameters": {
"env": {
"Type": "String"
}
},
希望这对您有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。