繁体   English   中英

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

[英]"Parameter values specified for a template which does not require them." when trying to deploy a conformance pack via 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中指定的参数)传递给 CloudFormation 模板(在TemplateBody中指定的参数),该模板不包含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"
        }
    },

希望这对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM