AWS ElastiCache Cluster
This page shows how to write Terraform and CloudFormation for ElastiCache Cluster and write them securely.
aws_elasticache_cluster (Terraform)
The Cluster in ElastiCache can be configured in Terraform with the resource name aws_elasticache_cluster. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_elasticache_cluster" "noMemcachedInElastiCache" {
cluster_id = "cluster-example"
engine = "memcached"
node_type = "cache.m4.large"
num_cache_nodes = 2
parameter_group_name = "default.memcached1.4"
resource "aws_elasticache_cluster" "enabled" {
cluster_id = "cluster"
engine = "redis"
node_type = "cache.m5.large"
num_cache_nodes = 1
parameter_group_name = "default.redis6.x"
resource "aws_elasticache_cluster" "memcached" {
cluster_id = "cluster-example"
engine = "memcached"
node_type = "cache.m4.large"
num_cache_nodes = 2
parameter_group_name = "default.redis3.2"
resource "aws_elasticache_cluster" "enabled" {
cluster_id = "cluster"
engine = "redis"
node_type = "cache.m5.large"
num_cache_nodes = 1
parameter_group_name = "default.redis6.x"
resource "aws_elasticache_cluster" "enabled" {
cluster_id = "cluster"
engine = "redis"
node_type = "cache.m5.large"
num_cache_nodes = 1
parameter_group_name = "default.redis6.x"
Security Best Practices for aws_elasticache_cluster
There is 1 setting in aws_elasticache_cluster that should be taken care of for security reasons. The following section explain an overview and example code.
Ensure to enable backup retention of Elasitcache
It's better to take snapshots of Redis clusters to improve data availability.
Parameters
-
apply_immediatelyoptional computed - bool -
arnoptional computed - string -
availability_zoneoptional computed - string -
az_modeoptional computed - string -
cache_nodesoptional computed - list of object-
address- string -
availability_zone- string -
id- string -
port- number
-
-
cluster_addressoptional computed - string -
cluster_idrequired - string -
configuration_endpointoptional computed - string -
engineoptional computed - string -
engine_versionoptional computed - string -
final_snapshot_identifieroptional - string -
idoptional computed - string -
maintenance_windowoptional computed - string -
node_typeoptional computed - string -
notification_topic_arnoptional - string -
num_cache_nodesoptional computed - number -
parameter_group_nameoptional computed - string -
portoptional computed - number -
preferred_availability_zonesoptional - list of string -
replication_group_idoptional computed - string -
security_group_idsoptional computed - set of string -
security_group_namesoptional computed - set of string -
snapshot_arnsoptional - list of string -
snapshot_nameoptional - string -
snapshot_retention_limitoptional - number -
snapshot_windowoptional computed - string -
subnet_group_nameoptional computed - string -
tagsoptional - map from string to string
Explanation in Terraform Registry
Provides an ElastiCache Cluster resource, which manages either a Memcached cluster, a single-node Redis instance, or a [read replica in a Redis (Cluster Mode Enabled) replication group]. For working with Redis (Cluster Mode Enabled) replication groups, see the
aws_elasticache_replication_groupresource.Note: When you change an attribute, such as
num_cache_nodes, by default it is applied in the next maintenance window. Because of this, Terraform may report a difference in its planning phase because the actual modification has not yet taken place. You can use theapply_immediatelyflag to instruct the service to apply the change immediately. Usingapply_immediatelycan result in a brief downtime as the server reboots. See the AWS Documentation on Modifying an ElastiCache Cache Cluster for ElastiCache for Memcached or ElastiCache for Redis for more information. Note: Any attribute changes that re-create the resource will be applied immediately, regardless of the value ofapply_immediately.
Tips: Best Practices for The Other AWS ElastiCache Resources
In addition to the aws_elasticache_replication_group, AWS ElastiCache has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_elasticache_replication_group
Ensure to enable in-transit encryption of ElastiCache
It's better to enable in-transit encryption of ElastiCahe. If the ElastiCache replication group uses unencrypted traffic, it is vulnerable to meet-in-the-middle (MITM) attacks.
AWS::ElastiCache::CacheCluster (CloudFormation)
The CacheCluster in ElastiCache can be configured in CloudFormation with the resource name AWS::ElastiCache::CacheCluster. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
AZModeoptional - String -
AutoMinorVersionUpgradeoptional - Boolean -
CacheNodeTyperequired - String -
CacheParameterGroupNameoptional - String -
CacheSecurityGroupNamesoptional - List -
CacheSubnetGroupNameoptional - String -
ClusterNameoptional - String -
Enginerequired - String -
EngineVersionoptional - String -
LogDeliveryConfigurationsoptional - List of LogDeliveryConfigurationRequest -
NotificationTopicArnoptional - String -
NumCacheNodesrequired - Integer -
Portoptional - Integer -
PreferredAvailabilityZoneoptional - String -
PreferredAvailabilityZonesoptional - List -
PreferredMaintenanceWindowoptional - String -
SnapshotArnsoptional - List -
SnapshotNameoptional - String -
SnapshotRetentionLimitoptional - Integer -
SnapshotWindowoptional - String -
Tagsoptional - List of Tag -
VpcSecurityGroupIdsoptional - List
Explanation in CloudFormation Registry
The AWS::ElastiCache::CacheCluster type creates an Amazon ElastiCache cache cluster.
Frequently asked questions
What is AWS ElastiCache Cluster?
AWS ElastiCache Cluster is a resource for ElastiCache of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS ElastiCache Cluster?
For Terraform, the storebot/pr_demo_flat, melscoop-test/check and gilyas/infracost source code examples are useful. See the Terraform Example section for further details.