Amazon ElastiCache for Memcached
Overview
This service contains code to deploy a Memcached Cluster using Amazon ElastiCache. The cluster is managed by AWS and automatically handles automatic node discovery, recovery from failures, patching, and the ability to scale to large clusters of nodes.
ElastiCache for Memcached architecture
Features
- Deploy a fully-managed Memcached cluster
- Automatic detection and recovery from cache node failures
- Automatic discovery of nodes within a cluster
- CloudWatch Alarms for alerting when CPU, memory, and disk metrics exceed certain thresholds
- Integrate with Kubernetes Service Discovery
Learn
This repo is a part of the Gruntwork Service Catalog, a collection of reusable, battle-tested, production ready infrastructure code. If you’ve never used the Service Catalog before, make sure to read How to use the Gruntwork Service Catalog!
-
Amazon ElastiCache for Memcached documentation: Amazon’s ElastiCache for Memcached docs that cover core concepts such as the options and versions supported, security, backup & restore, and monitoring.
-
Designing Data Intensive Applications: the best book we’ve found for understanding data systems, including relational databases, NoSQL, replication, sharding, consistency, and so on.
Deploy
Non-production deployment (quick start for learning)
If you just want to try this repo out for experimenting and learning, check out the following resources:
- examples/for-learning-and-testing folder: The
examples/for-learning-and-testing
folder contains standalone sample code optimized for learning, experimenting, and testing (but not direct production usage).
Production deployment
If you want to deploy this repo in production, check out the following resources:
- examples/for-production folder: The
examples/for-production
folder contains sample code optimized for direct usage in production. This is code from the Gruntwork Reference Architecture, and it shows you how we build an end-to-end, integrated tech stack on top of the Gruntwork Service Catalog.
Sample Usage
- Terraform
- Terragrunt
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S MEMCACHED MODULE
# ------------------------------------------------------------------------------------------------------
module "memcached" {
source = "git::git@github.com:gruntwork-io/terraform-aws-service-catalog.git//modules/data-stores/memcached?ref=v0.118.1"
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# Specifies whether the nodes in this Memcached node group are created in a
# single Availability Zone or created across multiple Availability Zones in
# the cluster's region. Valid values for this parameter are single-az or
# cross-az. If you want to choose cross-az, num_cache_nodes must be greater
# than 1.
az_mode = <string>
# The compute and memory capacity of the nodes (e.g. cache.m4.large).
instance_type = <string>
# The name used to namespace all resources created by these templates,
# including the ElastiCache cluster itself. Must be unique in this region.
# Must be a lowercase string.
name = <string>
# The initial number of cache nodes that the cache cluster will have. Must be
# between 1 and 20.
num_cache_nodes = <number>
# The list of IDs of the subnets in which to deploy the ElasticCache
# instances. The list must only contain subnets in var.vpc_id.
subnet_ids = <list(string)>
# The ID of the VPC in which to deploy RDS.
vpc_id = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Sets how this alarm should handle entering the INSUFFICIENT_DATA state.
# Based on
# https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-missing-data.
# Must be one of: 'missing', 'ignore', 'breaching' or 'notBreaching'.
alarm_treat_missing_data = "missing"
# The ARNs of SNS topics where CloudWatch alarms (e.g., for CPU, memory, and
# disk space usage) should send notifications.
alarms_sns_topic_arns = []
# The list of network CIDR blocks to allow network access to ElastiCache from.
# One of var.allow_connections_from_cidr_blocks or
# var.allow_connections_from_security_groups must be specified for the
# ElastiCache instances to be reachable.
allow_connections_from_cidr_blocks = []
# The list of IDs or Security Groups to allow network access to ElastiCache
# from. All security groups must either be in the VPC specified by var.vpc_id,
# or a peered VPC with the VPC specified by var.vpc_id. One of
# var.allow_connections_from_cidr_blocks or
# var.allow_connections_from_security_groups must be specified for the
# ElastiCache instances to be reachable.
allow_connections_from_security_groups = []
# Specifies whether any database modifications are applied immediately, or
# during the next maintenance window.
apply_immediately = false
# Set to true to enable several basic CloudWatch alarms around CPU usage,
# memory usage, and disk space usage. If set to true, make sure to specify SNS
# topics to send notifications to using var.alarms_sns_topic_arn.
enable_cloudwatch_alarms = true
# Specifies the weekly time range for when maintenance on the cache cluster is
# performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi
# (24H Clock UTC). The minimum maintenance window is a 60 minute period.
maintenance_window = "sat:07:00-sat:08:00"
# Version number of memcached to use (e.g. 1.5.16).
memcached_version = "1.5.16"
# The port number on which each of the cache nodes will accept connections
# (e.g. 11211).
port = 11211
}
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S MEMCACHED MODULE
# ------------------------------------------------------------------------------------------------------
terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-service-catalog.git//modules/data-stores/memcached?ref=v0.118.1"
}
inputs = {
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# Specifies whether the nodes in this Memcached node group are created in a
# single Availability Zone or created across multiple Availability Zones in
# the cluster's region. Valid values for this parameter are single-az or
# cross-az. If you want to choose cross-az, num_cache_nodes must be greater
# than 1.
az_mode = <string>
# The compute and memory capacity of the nodes (e.g. cache.m4.large).
instance_type = <string>
# The name used to namespace all resources created by these templates,
# including the ElastiCache cluster itself. Must be unique in this region.
# Must be a lowercase string.
name = <string>
# The initial number of cache nodes that the cache cluster will have. Must be
# between 1 and 20.
num_cache_nodes = <number>
# The list of IDs of the subnets in which to deploy the ElasticCache
# instances. The list must only contain subnets in var.vpc_id.
subnet_ids = <list(string)>
# The ID of the VPC in which to deploy RDS.
vpc_id = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Sets how this alarm should handle entering the INSUFFICIENT_DATA state.
# Based on
# https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-missing-data.
# Must be one of: 'missing', 'ignore', 'breaching' or 'notBreaching'.
alarm_treat_missing_data = "missing"
# The ARNs of SNS topics where CloudWatch alarms (e.g., for CPU, memory, and
# disk space usage) should send notifications.
alarms_sns_topic_arns = []
# The list of network CIDR blocks to allow network access to ElastiCache from.
# One of var.allow_connections_from_cidr_blocks or
# var.allow_connections_from_security_groups must be specified for the
# ElastiCache instances to be reachable.
allow_connections_from_cidr_blocks = []
# The list of IDs or Security Groups to allow network access to ElastiCache
# from. All security groups must either be in the VPC specified by var.vpc_id,
# or a peered VPC with the VPC specified by var.vpc_id. One of
# var.allow_connections_from_cidr_blocks or
# var.allow_connections_from_security_groups must be specified for the
# ElastiCache instances to be reachable.
allow_connections_from_security_groups = []
# Specifies whether any database modifications are applied immediately, or
# during the next maintenance window.
apply_immediately = false
# Set to true to enable several basic CloudWatch alarms around CPU usage,
# memory usage, and disk space usage. If set to true, make sure to specify SNS
# topics to send notifications to using var.alarms_sns_topic_arn.
enable_cloudwatch_alarms = true
# Specifies the weekly time range for when maintenance on the cache cluster is
# performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi
# (24H Clock UTC). The minimum maintenance window is a 60 minute period.
maintenance_window = "sat:07:00-sat:08:00"
# Version number of memcached to use (e.g. 1.5.16).
memcached_version = "1.5.16"
# The port number on which each of the cache nodes will accept connections
# (e.g. 11211).
port = 11211
}
Reference
- Inputs
- Outputs
Required
az_mode
stringSpecifies whether the nodes in this Memcached node group are created in a single Availability Zone or created across multiple Availability Zones in the cluster's region. Valid values for this parameter are single-az or cross-az. If you want to choose cross-az, num_cache_nodes must be greater than 1.
instance_type
stringThe compute and memory capacity of the nodes (e.g. cache.m4.large).
name
stringThe name used to namespace all resources created by these templates, including the ElastiCache cluster itself. Must be unique in this region. Must be a lowercase string.
num_cache_nodes
numberThe initial number of cache nodes that the cache cluster will have. Must be between 1 and 20.
subnet_ids
list(string)The list of IDs of the subnets in which to deploy the ElasticCache instances. The list must only contain subnets in vpc_id
.
vpc_id
stringThe ID of the VPC in which to deploy RDS.
Optional
alarm_treat_missing_data
stringSets how this alarm should handle entering the INSUFFICIENT_DATA state. Based on https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-missing-data. Must be one of: 'missing', 'ignore', 'breaching' or 'notBreaching'.
"missing"
alarms_sns_topic_arns
list(string)The ARNs of SNS topics where CloudWatch alarms (e.g., for CPU, memory, and disk space usage) should send notifications.
[]
allow_connections_from_cidr_blocks
list(string)The list of network CIDR blocks to allow network access to ElastiCache from. One of allow_connections_from_cidr_blocks
or allow_connections_from_security_groups
must be specified for the ElastiCache instances to be reachable.
[]
allow_connections_from_security_groups
list(string)The list of IDs or Security Groups to allow network access to ElastiCache from. All security groups must either be in the VPC specified by vpc_id
, or a peered VPC with the VPC specified by vpc_id
. One of allow_connections_from_cidr_blocks
or allow_connections_from_security_groups
must be specified for the ElastiCache instances to be reachable.
[]
Specifies whether any database modifications are applied immediately, or during the next maintenance window.
false
Set to true to enable several basic CloudWatch alarms around CPU usage, memory usage, and disk space usage. If set to true, make sure to specify SNS topics to send notifications to using alarms_sns_topic_arn
.
true
maintenance_window
stringSpecifies the weekly time range for when maintenance on the cache cluster is performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period.
"sat:07:00-sat:08:00"
memcached_version
stringVersion number of memcached to use (e.g. 1.5.16).
"1.5.16"
port
numberThe port number on which each of the cache nodes will accept connections (e.g. 11211).
11211
The list of addresses of the Memcached nodes without the port appended.
The id of the ElastiCache Memcached cluster.
The list of the AWS cache cluster node ids where each one represents a Memcached node.
The port number on which each of the cache nodes will accept connections (e.g. 11211).
The configuration endpoint to allow host discovery.