【问题标题】:aws cdk for Elasticache Redis Cluster用于 Elasticache Redis 集群的 aws cdk
【发布时间】:2019-10-14 06:39:50
【问题描述】:

我已经通过https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_elasticache.html

如何使用 AWS-CDK 创建 Elasticache Redis 模板。如果您分享示例代码会更有帮助。

【问题讨论】:

    标签: aws-cdk


    【解决方案1】:

    抱歉回复晚了,但对其他人有用。

    CDK 没有 High Level Construct 来创建 Redis 集群,但是您可以使用 Low Level Construct api 来创建它。

    对于 Redis 集群类型,您可以查看:https://aws.amazon.com/it/blogs/database/work-with-cluster-mode-on-amazon-elasticache-for-redis/

    我使用 typescript 创建了一个 Redis(无复制)集群,如下所示:

    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);
    

    如果您需要 Redis (已启用集群) 集群,您可以复制组

    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);
    

    希望对您有所帮助。

    【讨论】:

    • 为确保在复制组之前创建子网组,我将 cacheSubnetGroupName 更改为:cacheSubnetGroupName: redisSubnetGroup.ref。否则,我看到生成的 cloudformation 模板没有任何 cacheSubnetGroupName,因此该组将在您的默认子网中创建,或者,如果您的 VPC 中没有,您将收到错误“该帐户没有任何默认值子网”。
    【解决方案2】:

    我花了好几个小时才创建一个启用了一个分片但两个节点的 Redis 集群模式。如果您创建一个 num_cache_clusters=2 的 CfnReplicationGroup,它将创建一个主节点和副本节点。

    诀窍是创建一个 num_cache_clusters=2 的 CfnReplicationGroup 并设置 cache_parameter_group_name="default.redis6.x.cluster.on"

    然后会创建一个启用集群模式的redis缓存,一个分片两个节点

    【讨论】:

      猜你喜欢
      • 2021-02-05
      • 2018-05-03
      • 2019-09-12
      • 1970-01-01
      • 2022-10-20
      • 2019-07-13
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      相关资源
      最近更新 更多