Friday 18 May 2018

Working with 20+ node ElastiCache Memcached clusters

ElastiCache Memcached limits the number of nodes in a cluster to 20 by default. This limit can be increased with ElastiCache recommending against clusters larger than 50 nodes.

The increased cluster node limits don't reflect in the console so even after the limit has been increased the maximum number of nodes you can select when creating a new cluster is 20. Fortunately the CLI allows you to work around this and you can tweak the examples in the ElastiCache cluster creation documentation to achieve your desired outcome. Creating a cluster with more than 20 nodes using the CLI:

$ aws elasticache create-cache-cluster --cache-cluster-id my-super-cluster --cache-node-type cache.t2.micro --engine memcached --engine-version 1.4.34 --cache-parameter-group default.memcached1.4 --num-cache-nodes 30
{
    "CacheCluster": {
        "CacheClusterId": "my-super-cluster",
        "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:",
        "CacheNodeType": "cache.t2.micro",
        "Engine": "memcached",
        "EngineVersion": "1.4.34",
        "CacheClusterStatus": "creating",
        "NumCacheNodes": 30,
        "PreferredMaintenanceWindow": "mon:02:30-mon:03:30",
        "PendingModifiedValues": {},
        "CacheSecurityGroups": [],
        "CacheParameterGroup": {
            "CacheParameterGroupName": "default.memcached1.4",
            "ParameterApplyStatus": "in-sync",
            "CacheNodeIdsToReboot": []
        },
        "CacheSubnetGroupName": "default",
        "AutoMinorVersionUpgrade": true,
        "TransitEncryptionEnabled": false,
        "AtRestEncryptionEnabled": false
    }
}

Adding nodes can be done via the console as it allows you to specify the number of nodes rather than selecting from a drop down. For completeness this can also be done via the CLI:

$ aws elasticache modify-cache-cluster --cache-cluster-id test-limits --num-cache-nodes 26 --apply-immediately
{
    "CacheCluster": {
        "CacheClusterId": "test-limits",
        "ConfigurationEndpoint": {
            "Address": "test-limits.rftr8g.cfg.euw1.cache.amazonaws.com",
            "Port": 11211
        },
        "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:",
        "CacheNodeType": "cache.t2.micro",
        "Engine": "memcached",
        "EngineVersion": "1.4.34",
        "CacheClusterStatus": "modifying",
        "NumCacheNodes": 6,
        "PreferredAvailabilityZone": "Multiple",
        "CacheClusterCreateTime": "2018-05-18T07:10:22.530Z",
        "PreferredMaintenanceWindow": "sat:23:30-sun:00:30",
        "PendingModifiedValues": {
            "NumCacheNodes": 26
        },
        "CacheSecurityGroups": [],
        "CacheParameterGroup": {
            "CacheParameterGroupName": "default.memcached1.4",
            "ParameterApplyStatus": "in-sync",
            "CacheNodeIdsToReboot": []
        },
        "CacheSubnetGroupName": "default",
        "AutoMinorVersionUpgrade": true,
        "SecurityGroups": [
            {
                "SecurityGroupId": "sg-5814fd37",
                "Status": "active"
            }
        ],
        "TransitEncryptionEnabled": false,
        "AtRestEncryptionEnabled": false
    }
}


And finally removing nodes via the CLI (note the spaces rather than commas between the node IDs):

$ aws elasticache modify-cache-cluster --cache-cluster-id test-limits --num-cache-nodes 6 --cache-node-ids-to-remove 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 --apply-immediately  
{
    "CacheCluster": {
        "CacheClusterId": "test-limits",
        "ConfigurationEndpoint": {
            "Address": "test-limits.rftr8g.cfg.euw1.cache.amazonaws.com",
            "Port": 11211
        },
        "ClientDownloadLandingPage": "https://console.aws.amazon.com/elasticache/home#client-download:",
        "CacheNodeType": "cache.t2.micro",
        "Engine": "memcached",
        "EngineVersion": "1.4.34",
        "CacheClusterStatus": "modifying",
        "NumCacheNodes": 26,
        "PreferredAvailabilityZone": "Multiple",
        "CacheClusterCreateTime": "2018-05-18T07:10:22.530Z",
        "PreferredMaintenanceWindow": "sat:23:30-sun:00:30",
        "PendingModifiedValues": {
            "NumCacheNodes": 6,
            "CacheNodeIdsToRemove": [
                "0007",
                "0008",
                "0009",
                "0010",
                "0011",
                "0012",
                "0013",
                "0014",
                "0015",
                "0016",
                "0017",
                "0018",
                "0019",
                "0020",
                "0021",
                "0022",
                "0023",
                "0024",
                "0025",
                "0026"
            ]
        },
        "CacheSecurityGroups": [],
        "CacheParameterGroup": {
            "CacheParameterGroupName": "default.memcached1.4",
            "ParameterApplyStatus": "in-sync",
            "CacheNodeIdsToReboot": []
        },
        "CacheSubnetGroupName": "default",
        "AutoMinorVersionUpgrade": true,
        "SecurityGroups": [
            {
                "SecurityGroupId": "sg-5814fd37",
                "Status": "active"
            }
        ],
        "TransitEncryptionEnabled": false,
        "AtRestEncryptionEnabled": false
    }
}