Zaid Afaneh
Zaid Afaneh

Reputation: 154

Invalid Parameter Combination when creating a new Elasticache Redis Instance using Cloudformation

I am creating a new stack which includes a Redis instance, after starting the creation, I get this error for redis:

Cannot use the given parameters when creating new replication group in an existing global replication group. (Service: AmazonElastiCache; Status Code: 400; Error Code: InvalidParameterCombination;

I am new to using elasticache within cloudformation and the documentation doesn't provide a lot of helpful information for the valid/correct combination.

I am using the following snippet:

cachesubnet:
  Type: AWS::ElastiCache::SubnetGroup
  Properties: 
    CacheSubnetGroupName: !Join ["-" , ["rb", !Ref Environment, "redis-subnet-group"]]
    Description: subnet group for redis 
    SubnetIds:
      - !Ref private1a
      - !Ref private1b
    Tags: 
      - Key: environment
        Value: !Ref Environment
redis2: 
  Type: AWS::ElastiCache::ReplicationGroup
  Properties: 
    AtRestEncryptionEnabled: True
    AutomaticFailoverEnabled: True
    AutoMinorVersionUpgrade: True
    CacheNodeType: cache.m5.large
    CacheParameterGroupName: default.redis5.0
    CacheSubnetGroupName: !Ref cachesubnet
    Engine: redis
    EngineVersion: 5.0.6
    NumNodeGroups: 1
    GlobalReplicationGroupId: !Join ["-" , ["rb-horizon", !Ref Environment]]
    MultiAZEnabled: True
    NodeGroupConfiguration:
      - PrimaryAvailabilityZone: us-east-1a
      - ReplicaAvailabilityZones: 
        - us-east-1b
      - ReplicaCount: 1
    PreferredCacheClusterAZs: 
      - us-east-1a
      - us-east-1b
    PreferredMaintenanceWindow: mon:06:30-mon:07:30
    ReplicationGroupDescription: Horizon for env
    ReplicationGroupId: !Join ["-" , ["rb-horizon", !Ref Environment, rgi]]
    SecurityGroupIds: 
      - !GetAtt mainSecGroup.GroupId
    Tags: 
      - Key: environment
        Value: !Ref Environment

Upvotes: 1

Views: 4366

Answers (1)

chetan
chetan

Reputation: 350

Ran into a similar issue today and was able to solve it via some information gleaned from this thread https://old.reddit.com/r/aws/comments/rvgv15/demystifying_redis_in_cloudformation_multiaz_and/

You do not need to specify parameters such as Engine, EngineVersion, CacheNodeType, etc... because ElastiCache will know to use the same values as the ones provided in the primary replication group of the global datastore.

While it says there that the params are not needed, they actually do raise the above error message. I added a condition around those fields and then my stack went through fine.

// edited to add example below

Example redis template. I removed the mappings and snipped the security group ingress rules which are not relevant for demonstration purposes.

The GlobalReplicationGroupId param should not be set for the PRIMARY redis group. Instead, the PRIMARY is joined to the global data store while creating the GlobalReplicationGroup. You should only add the primary member in that resource.

For creating the secondary groups, first launch redis with this param empty and then update it with the param pointing to the previously created GlobalReplicationGroup to join the global store.

    {
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "GlobalReplicationGroupId": {
            "Description": "ID of the previously created Global Replication Group (optional)",
            "Type": "String",
            "Default": ""
        }
    },

    "Conditions": {
        "IsGlobalStore": {
            "Fn::Not": [{
                "Fn::Equals": [ { "Ref": "GlobalReplicationGroupId" }, "" ]
            }]
        }
    },

    "Resources": {
        "RedisParameterGroup": {
            "Type": "AWS::ElastiCache::ParameterGroup",
            "Properties": {
                "CacheParameterGroupFamily": "redis6.x",
                "Description": {
                    "Fn::Join": [
                        "",
                        [
                            "Redis Parameter Group ",
                            {
                                "Ref": "EnvironmentName"
                            }
                        ]
                    ]
                }
            }
        },
        "RedisSubnetGroup": {
            "Type": "AWS::ElastiCache::SubnetGroup",
            "Properties": {
                "CacheSubnetGroupName": {
                    "Fn::Join": [
                        "", [
                            "", { "Ref": "EnvironmentName" }, "-redis-subnet-group"
                        ]
                    ]
                },
                "SubnetIds": {
                    "Fn::FindInMap": [
                        "privateSubnets",
                        {
                            "Ref": "AWS::Region"
                        },
                        {
                            "Ref": "EnvironmentName"
                        }
                    ]
                },
                "Description": {
                    "Fn::Join": [
                        "",
                        [
                            "Redis Subnet Group ",
                            {
                                "Ref": "EnvironmentName"
                            }
                        ]
                    ]
                }
            }
        },
        "RedisSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": {
                    "Fn::Join": [
                        "",
                        [
                            "Redis Security Group ",
                            {
                                "Ref": "EnvironmentName"
                            }
                        ]
                    ]
                },
                "VpcId": {
                    "Fn::FindInMap": [
                        "vpcId",
                        {
                            "Ref": "AWS::Region"
                        },
                        {
                            "Ref": "EnvironmentName"
                        }
                    ]
                },
                "SecurityGroupIngress": [
                ],
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "",
                                [
                                    "Redis-",
                                    {
                                        "Ref": "EnvironmentName"
                                    },
                                    "-SecurityGroup"
                                ]
                            ]
                        }
                    },
                    {
                        "Key": "Product",
                        "Value": "Redis"
                    },
                    {
                        "Key": "Environment",
                        "Value": {
                            "Ref": "EnvironmentName"
                        }
                    }
                ]
            }
        },
        "RedisReplicationGroup": {
            "Type": "AWS::ElastiCache::ReplicationGroup",
            "Properties": {
                "GlobalReplicationGroupId": {
                    "Fn::If": [
                        "IsGlobalStore",
                        {"Ref": "GlobalReplicationGroupId"},
                        {"Ref": "AWS::NoValue"}
                    ]
                },

                "AutomaticFailoverEnabled": "true",
                "CacheNodeType": {
                    "Fn::If": [
                        "IsGlobalStore",
                        {
                            "Ref": "AWS::NoValue"
                        },
                        {
                            "Fn::FindInMap": [
                                "RedisNodeType",
                                {
                                    "Ref": "AWS::Region"
                                },
                                {
                                    "Ref": "EnvironmentName"
                                }
                            ]
                        }
                    ]
                },
                "CacheParameterGroupName": {
                    "Fn::If": [
                        "IsGlobalStore",
                        {
                            "Ref": "AWS::NoValue"
                        },
                        {
                            "Ref": "RedisParameterGroup"
                        }
                    ]
                },
                "CacheSubnetGroupName": {
                    "Ref": "RedisSubnetGroup"
                },
                "Engine": {
                    "Fn::If": [
                        "IsGlobalStore",
                        {
                            "Ref": "AWS::NoValue"
                        },
                        "redis"
                    ]
                },
                "EngineVersion": {
                    "Fn::If": [
                        "IsGlobalStore",
                        {
                            "Ref": "AWS::NoValue"
                        },
                        "6.2"
                    ]
                },
                "NumCacheClusters": {
                    "Fn::FindInMap": [
                        "NumCacheClusters",
                        {
                            "Ref": "AWS::Region"
                        },
                        {
                            "Ref": "EnvironmentName"
                        }
                    ]
                },
                "PreferredCacheClusterAZs": {
                    "Fn::FindInMap": [
                        "ZoneMap",
                        {
                            "Ref": "AWS::Region"
                        },
                        "AZ"
                    ]
                },
                "ReplicationGroupDescription": {
                    "Fn::Join": [
                        "",
                        [
                            "Redis Replication Group ",
                            {
                                "Ref": "EnvironmentName"
                            }
                        ]
                    ]
                },
                "SecurityGroupIds": [
                    {
                        "Ref": "RedisSecurityGroup"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "",
                                [
                                    "Redis-",
                                    {
                                        "Ref": "EnvironmentName"
                                    }
                                ]
                            ]
                        }
                    },
                    {
                        "Key": "Product",
                        "Value": "Redis"
                    },
                    {
                        "Key": "Environment",
                        "Value": {
                            "Ref": "EnvironmentName"
                        }
                    }
                ]
            }
        }
    },
    "Outputs": {}
}

Upvotes: 1

Related Questions