Creating Redis cluster enabled using AWS-CDK
In this post we are concentrating more on how to create redis cluster mode enabled.
Redis (cluster mode enabled) supports partitioning your data across up to 500 node groups. You can dynamically change the number of shards as your business needs change. One advantage of partitioning is that you spread your load over a greater number of endpoints, which reduces access bottlenecks during peak demand. Additionally, you can accommodate a larger data set since the data can be spread across multiple servers.
A node is the smallest building block of an ElastiCache deployment. A node can exist in isolation from or in some relationship to other nodes.
Every node within a cluster is the same instance type and runs the same cache engine. Multiple types of cache nodes are supported, each with varying amounts of associated memory.
You can purchase nodes on a pay-as-you-go basis, where you only pay for your use of a node. Or you can purchase reserved nodes at a much-reduced hourly rate. If your usage rate is high, purchasing reserved nodes can save you money. Suppose that your cluster is almost always in use, and you occasionally add nodes to handle use spikes.
const redisSubnetGroup = new elasticache.CfnSubnetGroup(this,`example-subnet-group`,{subnetIds: privateSubnetIds, // this is a private subnet id's, can find in VPCdescription: `example-subnet-group`,});const replicationGroup = new elasticache.CfnReplicationGroup(this,`example-redis`,{replicationGroupDescription: `example-redis`,// A flag indicating if you have Multi-AZ enabled to enhance fault tolerance.multiAzEnabled: true,// A flag that enables encryption at rest when set to true .atRestEncryptionEnabled: true,// Specifies whether a read-only replica is automatically promoted to read/write primary if the existing primary fails.automaticFailoverEnabled: true,// yes if you want to opt-in to the next minor version upgrade campaign.// Keeping it false for now.autoMinorVersionUpgrade: true,// The compute and memory capacity of the nodes in the node group (shard).cacheNodeType: "cache.r6g.large",// The name of the cache engine to be used for the clusters in this replication group.engine: "Redis",// The name of the parameter group to associate with this replication group.cacheParameterGroupName: "default.redis6.x.cluster.on",// The version number of the cache engine to be used for the clusters in this replication group.engineVersion: "6.2",// The name of the cache subnet group to be used for the replication group.cacheSubnetGroupName: redisSubnetGroup.ref,// One or more Amazon VPC security groups associated with this replication group.// A flag that enables in-transit encryption when set to true .transitEncryptionEnabled: false,port: 6379,// An optional parameter that specifies the number of node groups (shards)// for this Redis (cluster mode enabled) replication group.numNodeGroups: 1,// An optional parameter that specifies the number of replica nodes in each node group (shard).replicasPerNodeGroup: 1,});
We first need to create SubnetGroup.
AWS-CDK exposes L1 construct CfnReplicationGroup under aws-cdk-lib/aws-elasticache.
There are wide range of configurations in this construct but the above configurations are good enough to create the Redis with default configurations. For more information check AWS.
No comments:
Post a Comment
If you have any doubts, Please let me know