简体   繁体   中英

aws cdk for Elasticache Redis Cluster

I have gone through the https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_elasticache.html .

How to create an Elasticache Redis template using AWS-CDK. It would be more helpful if you share the sample code.

sorry for late response but can be usefull for others.

CDK doesn't have an High Level Construct to create a Redis Cluster, but you can create it by using the low level construct api.

For Redis Cluster types you can take a look at this: https://aws.amazon.com/it/blogs/database/work-with-cluster-mode-on-amazon-elasticache-for-redis/

I've created a single Redis (no replication) Cluster using typescript like this:

const subnetGroup = new CfnSubnetGroup(
  this,
  "RedisClusterPrivateSubnetGroup",
  {
    cacheSubnetGroupName: "privata",
    subnetIds: privateSubnets.subnetIds,
    description: "subnet di sviluppo privata"
  }
);
const redis = new CfnCacheCluster(this, `RedisCluster`, {
  engine: "redis",
  cacheNodeType: "cache.t2.small",
  numCacheNodes: 1,
  clusterName: "redis-sviluppo",
  vpcSecurityGroupIds: [vpc.defaultSecurityGroup.securityGroupId],
  cacheSubnetGroupName: subnetGroup.cacheSubnetGroupName
});
redis.addDependsOn(subnetGroup);

If you need a Redis (cluster enabled) Cluster you can you replication group

const redisSubnetGroup = new CfnSubnetGroup(
  this,
  "RedisClusterPrivateSubnetGroup",
  {
    cacheSubnetGroupName: "privata",
    subnetIds: privateSubnets.subnetIds,
    description: "subnet di produzione privata"
  }
);

const redisReplication = new CfnReplicationGroup(
  this,
  `RedisReplicaGroup`,
  {
    engine: "redis",
    cacheNodeType: "cache.m5.xlarge",
    replicasPerNodeGroup: 1,
    numNodeGroups: 3,
    automaticFailoverEnabled: true,
    autoMinorVersionUpgrade: true,
    replicationGroupDescription: "cluster redis di produzione",
    cacheSubnetGroupName: redisSubnetGroup.cacheSubnetGroupName
  }
);
redisReplication.addDependsOn(redisSubnetGroup);

Hope this help.

I just struggled for hours creating a Redis cluster mode enabled with just one shard but two nodes. If you create a CfnReplicationGroup with num_cache_clusters=2, it will create a primary & replica node.

The trick is to create a CfnReplicationGroup with num_cache_clusters=2 and set the cache_parameter_group_name="default.redis6.x.cluster.on"

Then it will create a redis cache with cluster mode enable, one shard but two nodes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM