【问题标题】:"Parameter values specified for a template which does not require them." when trying to deploy a conformance pack via AWS cloudformation“为不需要它们的模板指定的参数值。”尝试通过 AWS cloudformation 部署一致性包时
【发布时间】:2020-11-11 21:59:25
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    原因是您将参数(ConformancePackInputParameters 中指定的参数)传递给不包含Parameters 部分的 CloudFormation 模板(TemplateBody 中指定的参数),因此不需要任何参数。为了解决这个问题,您需要在内部 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
    

    【讨论】:

      【解决方案2】:

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

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

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

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

      希望这对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2020-10-25
        • 2023-04-11
        • 2020-10-23
        • 2020-05-19
        • 2020-04-10
        • 2020-12-02
        • 2017-05-25
        • 2021-10-05
        • 1970-01-01
        相关资源
        最近更新 更多