首页 > 解决方案 > Cloudformation for redis 参数组

问题描述

我想创建一个 cloudformation 模板来部署一个 redis 参数组。问题在于我的每个参数看起来像这样:

{
    "Parameters": [
        {
            "ParameterName": "activedefrag",
            "ParameterValue": "no",
            "Description": "Enabled active memory defragmentation",
            "Source": "user",
            "DataType": "string",
            "AllowedValues": "yes,no",
            "IsModifiable": true,
            "MinimumEngineVersion": "4.0.9",
            "ChangeType": "immediate"
        },
        {
            "ParameterName": "active-defrag-cycle-max",
            "ParameterValue": "75",
            "Description": "Maximal effort for defrag in CPU percentage",
            "Source": "user",
            "DataType": "integer",
            "AllowedValues": "1-75",
            "IsModifiable": true,
            "MinimumEngineVersion": "4.0.9",
            "ChangeType": "immediate"
        }
}

现在我了解了模板的基本格式,但不知道如何传入参数,如上所示。

失败的模板:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Template to create a consul cluster",
  "Parameters": {
    "CacheParameterGroupFamily": {
      "Description": "The name of the cache parameter group family that this cache parameter group is compatible with.",
      "Type": "String",
      "Default": "redis4.0",
      "AllowedValues": ["memcached1.4", "memcached1.5", "redis2.6", "redis2.8", "redis3.2", "redis4.0", "redis5.0"]
    },
    "ParameterGroupDescription": {
      "Description": "What this parameter group will be used for",
      "Type": "String"
    }
  },
  "Resources": {
    "RedisParameterGroup": {
      "Type": "AWS::ElastiCache::ParameterGroup",
      "Properties": {
        "CacheParameterGroupFamily" : { "Ref": "CacheParameterGroupFamily" },
        "Description" : { "Ref": "ParameterGroupDescription" },
        "Properties" : {
            "Parameters": [{
                "ParameterName": "activedefrag",
                "ParameterValue": "no",
                "Description": "Enabled active memory defragmentation",
                "Source": "user",
                "DataType": "string",
                "AllowedValues": "yes,no",
                "IsModifiable": true,
                "MinimumEngineVersion": "4.0.9",
                "ChangeType": "immediate"
            }]
        }
      }
    }
  }
}

标签: redisamazon-cloudformation

解决方案


欢迎来到 StackOverflow!

您需要将这些参数合并到Parameters模板部分中,并更改语法以使其符合参数格式

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Template to create a consul cluster",
  "Parameters": {
    "CacheParameterGroupFamily": {
      "Description": "The name of the cache parameter group family that this cache parameter group is compatible with.",
      "Type": "String",
      "Default": "redis4.0",
      "AllowedValues": ["memcached1.4", "memcached1.5", "redis2.6", "redis2.8", "redis3.2", "redis4.0", "redis5.0"]
    },
    "ParameterGroupDescription": {
      "Description": "What this parameter group will be used for",
      "Type": "String"
    },
    "activedefrag": {
        "Description": "Enabled active memory defragmentation",
        "Type": "String",
        "AllowedValues": ["yes", "no"],
        "Default": "no"
    },
    "activedefragcyclemax": {
        "Description": "Maximal effort for defrag in CPU percentage",
        "Type": "Number",
        "Default": 75,
        "MinValue": 1,
        "MaxValue": 75
    }
  },
  "Resources": {
    "RedisParameterGroup": {
      "Type": "AWS::ElastiCache::ParameterGroup",
      "Properties": {
        "CacheParameterGroupFamily" : { "Ref": "CacheParameterGroupFamily" },
        "Description" : { "Ref": "ParameterGroupDescription" },
        "Properties" : {
            "activedefrag": {"Ref": "activedefrag"},
            "active-defrag-cycle-max": {"Ref": "activedefragcyclemax"}
        }
      }
    }
  }
}

推荐阅读