用于 Elasticache Redis 集群的 aws cdk

Rag*_*dra 4 aws-cdk

我已经浏览了https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_elasticache.html

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

小智 17

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

CDK 没有用于创建 Redis 集群的高级构造,但您可以使用低级构造 api 来创建它。

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

我已经使用这样的打字稿创建了一个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);
Run Code Online (Sandbox Code Playgroud)

如果您需要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);
Run Code Online (Sandbox Code Playgroud)

希望这有帮助。

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