【问题标题】:Pass multiple parameters to DBParameterGroup in YAML CloudFormation将多个参数传递给 YAML CloudFormation 中的 DBParameterGroup
【发布时间】:2019-02-12 04:18:43
【问题描述】:

我有以下 cloudformation 模板。目标是仅在用户需要时创建参数组,然后使用 cloudformation 模板参数的内容填充参数组中的 RDS 参数。

Parameters:
  UseCustomParameterGroup:
    Description: Toggle to 'Yes' to create a new parameter group.
    Type: String
    AllowedValues: ['Yes', 'No']
    Default: 'No'
  CustomParameters:
    Description: Add custom parameters to your custom parameter group. Creating a custom parameter group without parameters creates a mirror of the default group.
    Type: String
Conditions:
  UseCustomParameterGroup: !Equals [!Ref 'UseCustomParameterGroup', 'Yes']
Resources:
  CustomParameterGroup:
    Type: AWS::RDS::DBParameterGroup
    Condition: 'UseCustomParameterGroup'
    Properties:
      Family: "postgres10"
      Parameters: !Ref "CustomParameters"

如果我这样从另一个模板调用此模板,它将失败并出现错误Value of property Parameters must be an object

Parameters:
  USECUSTOMPARAMETERGROUP: 'Yes'
  CUSTOMPARAMETERS: '{
    "shared_preload_libraries": "pg_stat_statements",
    "pg_stat_statements.track": "all"
  }'
Resources:
  Postgres:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: https://..../rds-postgres-instance.yaml
      TimeoutInMinutes: '60'
      Parameters:
        UseCustomParameterGroup: !Ref USECUSTOMPARAMETERGROUP
        CustomParameters: !Ref CUSTOMPARAMETERS

AWS::RDS::DBParameterGroup 的文档说明了 Parameters 参数的以下内容:

类型:由字符串键值对组成的 JSON 对象,如下例所示

“参数”:{“Key1”:“Value1”,“Key2”:“Value2”,“Key3”:“Value3”}

我认为这对于 Cloudformation 的 YAML 版本可能已经过时,但没有关于如何将此值传递给多个参数的文档。

我希望用户能够定义任意数量的 RDS 参数,而不必考虑 RDS 可用的数千个可能参数中的任何一个。

【问题讨论】:

    标签: yaml amazon-cloudformation


    【解决方案1】:

    Cloudformation 不允许您将字符串参数转换为 JSON 对象(或 YAML),您的参数旨在用作定义键的值。

    其他一些框架(如无服务器)通过使用不同的模板语言来克服此限制,该语言在经过一些处理后生成与 Cloudformation 兼容的工件,如果此功能对您的流程至关重要,我建议您迁移到其中一个框架。

    【讨论】:

    • 迁移不是一种选择。这是从我的组织继承而来的遗留堆栈。我通常更喜欢使用 terraform,但我没有选择取消它。
    猜你喜欢
    • 2019-03-15
    • 2021-09-18
    • 1970-01-01
    • 2021-01-07
    • 2016-07-18
    • 2013-01-07
    • 2011-10-10
    • 2013-09-15
    • 2010-10-09
    相关资源
    最近更新 更多