Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws cdk for Elasticache Redis Cluster

Tags:

aws-cdk

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.

like image 835
Raghavendra Avatar asked Oct 14 '19 06:10

Raghavendra


1 Answers

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.

like image 70
Stefano Corallo Avatar answered Oct 11 '22 06:10

Stefano Corallo