A cache cluster is one or more coordinated cache nodes that provide in-memory storage. In AWS, Amazon ElastiCache creates clusters using Redis or Memcached. The cluster sits between an application and its database, serving frequently read data with low latency and reducing database pressure. section 11.0 section 11.1.1
Game leaderboard
An online game can store player scores in a Redis sorted set, allowing the cache to sort and retrieve leaderboard entries quickly instead of repeatedly querying and sorting a relational database. Player profiles and other frequently read metadata can use the same in-memory layer. section 11.0
A minimal ElastiCache cluster specifies an engine, cache node type, node count, subnet group, and VPC security groups. Nodes use private IP addresses, so testing normally requires an EC2 instance in the same VPC. Security groups control network access; IAM controls cluster-management actions, while Redis can additionally provide user authentication and authorization. section 11.1.1 section 11.3.1
Listing 11.1 Minimal CloudFormation template of an ElastiCache Redis single-node cluster
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS in Action: chapter 11 (minimal)'
Parameters: #1
VPC:
Type: 'AWS::EC2::VPC::Id'
SubnetA:
Type: 'AWS::EC2::Subnet::Id'
SubnetB:
Type: 'AWS::EC2::Subnet::Id'
Resources:
CacheSecurityGroup: #2
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: cache
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp #3
FromPort: 6379
ToPort: 6379
CidrIp: '0.0.0.0/0'
CacheSubnetGroup: #4
Type: 'AWS::ElastiCache::SubnetGroup'
Properties:
Description: cache
SubnetIds:
- Ref: SubnetA #5
- Ref: SubnetB
Cache:
Type: 'AWS::ElastiCache::CacheCluster' #6
Properties:
CacheNodeType: 'cache.t2.micro' #7
CacheSubnetGroupName: !Ref CacheSubnetGroup
Engine: redis #8
NumCacheNodes: 1 #9
VpcSecurityGroupIds:
- !Ref CacheSecurityGroup
Use the minimal CloudFormation template to see the VPC parameters, cache subnet group, security group, and single-node Redis cluster assembled as deployable resources. section 11.1.1
