Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS cloudformation : how to properly create a redis cache cluster

I want to create an elasticache instance using redis.

I think that I should use it "cluster mode disabled" because everything will fit into one server. In order to not have a SPOF, I want to create a read replica that will be promoted by AWS in case of a failure of the master. If possible, it would be great to balance the read only operations between master and slave, but it is not mandatory.

I created a functioning master/read-replica using the aws console then used cloudformer to create the cloudformation json conf. Cloudformer has created me two unlinked AWS::ElastiCache::CacheCluster, but by reading the doc. I don't understand how to link them... For now I have this configuration :

{
    "cachehubcache001": {
      "Type": "AWS::ElastiCache::CacheCluster",
      "Properties": {
        "AutoMinorVersionUpgrade": "true",
        "AZMode": "single-az",
        "CacheNodeType": "cache.t2.small",
        "Engine": "redis",
        "EngineVersion": "3.2.4",
        "NumCacheNodes": "1",
        "PreferredAvailabilityZone": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "Az1B"]},
        "PreferredMaintenanceWindow": "sun:04:00-sun:05:00",
        "CacheSubnetGroupName": {
          "Ref": "cachesubnethubprivatecachesubnetgroup"
        },
        "VpcSecurityGroupIds": [
          {
            "Fn::GetAtt": [
              "sgiHubCacheSG",
              "GroupId"
            ]
          }
        ]
      }
    },
    "cachehubcache002": {
      "Type": "AWS::ElastiCache::CacheCluster",
      "Properties": {
        "AutoMinorVersionUpgrade": "true",
        "AZMode": "single-az",
        "CacheNodeType": "cache.t2.small",
        "Engine": "redis",
        "EngineVersion": "3.2.4",
        "NumCacheNodes": "1",
        "PreferredAvailabilityZone": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "Az1A"]},
        "PreferredMaintenanceWindow": "sun:02:00-sun:03:00",
        "CacheSubnetGroupName": {
          "Ref": "cachesubnethubprivatecachesubnetgroup"
        },
        "VpcSecurityGroupIds": [
          {
            "Fn::GetAtt": [
              "sgiHubCacheSG",
              "GroupId"
            ]
          }
        ]
      }
    },
}

I know that it is wrong, but I can't figure out how to create a correct replica. I can't understand the AWS doc, for a start I can't figure out wich Type I should use between :

  • http://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-replicationgroup.html
  • http://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-cache-cluster.html

Since cloudformer created AWS::ElastiCache::CacheCluster I'll go with it, but I've got the feeling that it should have created only one resource, and used the NumCacheNodes parameter in order to create two resources.

redis can't use :

  • NumCacheNodes
  • AZMode and PreferredAvailabilityZones

so I don't know how to make this solution multi-AZ...

like image 550
Bruno Avatar asked Jun 01 '17 08:06

Bruno


1 Answers

I managed to do this using AWS::ElastiCache::ReplicationGroup, the NumCacheClusters parameter provide the possibility to have numerous servers. Beware : it seem that you have to handle the connection to master/slave yourself (but in case of a master's failure, aws should normally detect it and change the dns of a slave to permit you point do not change your configuration). here is a sample :

"hubElastiCacheReplicationGroup" : {
      "Type" : "AWS::ElastiCache::ReplicationGroup",
      "Properties" : {
        "ReplicationGroupDescription" : "Hub WebServer redis cache cluster",
        "AutomaticFailoverEnabled" : "false",
        "AutoMinorVersionUpgrade" : "true",
        "CacheNodeType" : "cache.t2.small",
        "CacheParameterGroupName" : "default.redis3.2",
        "CacheSubnetGroupName" :  { "Ref": "cachesubnethubprivatecachesubnetgroup" },
        "Engine" : "redis",
        "EngineVersion" : "3.2.4",
        "NumCacheClusters" : { "Ref" : "ElasticacheRedisNumCacheClusters" },
        "PreferredMaintenanceWindow" : "sun:04:00-sun:05:00",
        "SecurityGroupIds" : [ { "Fn::GetAtt": ["sgHubCacheSG",  "GroupId"] } ]
      }
    },
like image 154
Bruno Avatar answered Dec 09 '22 16:12

Bruno