1
votes

I have the following cloudformation template. The goal is to only create a parameter group if the user wants to and then to populate the RDS parameters in the parameter group with the contents of the cloudformation template parameters.

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"

If I call this template from another template as so, it will fail with the error 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

The documentation for AWS::RDS::DBParameterGroup states the following for the Parameters parameter:

Type: A JSON object consisting of string key-value pairs, as shown in the following example

"Parameters" : { "Key1" : "Value1", "Key2" : "Value2", "Key3" : "Value3" }

I think this may be out of date for the YAML version of Cloudformation, but there is no documentation on how to pass this value multiple parameters.

I want the user to be able to define as few or many RDS parameters as they please without having to account for any of the thousands of possible parameters available to RDS.

1

1 Answers

0
votes

Cloudformation doesn't allow you to convert string parameters to JSON objects (or YAML for that matter), your parameters are meant to be used as values for your definition keys.

Some other frameworks like serverless overcome this limitation by using a different template language that generates a Cloudformation compatible artifact after some processing, if this feature is critical to your process I advise you to migrate to one of those frameworks.