“为不需要模板的模板指定了参数值。”尝试通过AWS cloudformation部署一致性包时

时间:2020-11-11 21:59:25

标签: amazon-web-services amazon-cloudformation aws-config

我正在研究通过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

2 个答案:

答案 0 :(得分:1)

原因是您将参数(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

答案 1 :(得分:0)

我在使用 cloudformation 制作测试用例资源时偶然发现了同样的错误。 “为不需要它们的模板指定的参数值。”

由于是测试用例,我根本没有使用任何参数。上面的答案有助于我理解它必须对参数做一些事情。即使您没有使用任何参数,在部署 cfn 时也会传递一些参数。

默认情况下,cloudformation 还将 env 作为参数发送,该参数需要在参数下。 (下面是 JSON 中的代码片段)

"Parameters": {
        "env": {
            "Type": "String"
        }
    },

希望这对您有所帮助。