amazon-web-services - AWS::ElastiCache::Global Replication Group 的 Cloudformation 模板

标签 amazon-web-services aws-cloudformation redis-cluster elastic-cache

想要使用 CF 创建 Redis 全局数据存储,遵循指南 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-globalreplicationgroup.html

但运气不好,我可以创建 Redis 集群,但不能创建全局数据存储: 我的代码:

AWSTemplateFormatVersion: '2010-09-09'
Description: redis deployment.
Parameters:
    RedisSubnets:
        Description: PRIVATE Subnets for subnet group
        Type: "List<String>"
    VpcId:
        Description: The VPC that the Postgres DB  is deployed to
        Type: AWS::EC2::VPC::Id
    NodeType:
        Description: Node type for redis service
        Type: String
    ClusterName:
        Description: Cluster name for redis service
        Type: String
    AvailabilityZones:
        Description: Availability zones for redis service
        Type: "List<String>"
    CidrIp1:
        Description: Ingress CIDr
        Type: String
        Default: 0.0.0.0/0
    CidrIp2:
        Description: Ingress CIDr
        Type: String
        Default: 0.0.0.0/0

Resources:
  RedisSubnetGroup:
    Type: AWS::ElastiCache::SubnetGroup
    Properties:
      CacheSubnetGroupName: !Sub ${AWS::StackName}-subnetgroup
      Description: "Subnet group for redis server"
      SubnetIds: !Ref RedisSubnets
  RedisSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: "A component security group allowing access only to redis"
  ElasticacheComponentSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "Elasticache security group"
      SecurityGroupIngress:
        -
          IpProtocol: "tcp"
          FromPort: 6379
          ToPort: 6379
          CidrIp: !Ref CidrIp1
        -
          IpProtocol: "tcp"
          FromPort: 6379
          ToPort: 6379
          CidrIp: !Ref CidrIp2
      VpcId: !Ref VpcId
  RedisService:
    Type: AWS::ElastiCache::ReplicationGroup
    Properties:
      AutoMinorVersionUpgrade: false
      CacheNodeType: cache.r5.large
      CacheParameterGroupName: default.redis6.x
      CacheSubnetGroupName: !Ref RedisSubnetGroup
      ReplicationGroupId: !Ref ClusterName
      SecurityGroupIds:
        - !Ref ElasticacheComponentSecurityGroup
      Engine: "Redis"
      EngineVersion: "6.2"
      NumNodeGroups: 1
      AutomaticFailoverEnabled: false
      ReplicationGroupDescription: Sample Redis group for scaling
      Port: 6379
  globalreplication:
    Type: AWS::ElastiCache::GlobalReplicationGroup
    Properties:
      AutomaticFailoverEnabled: false
      GlobalReplicationGroupDescription: description example
      GlobalReplicationGroupIdSuffix: test
      Members:
        - ReplicationGroupId: !Ref ClusterName
          ReplicationGroupRegion: eu-west-1
          Role: primary
      RegionalConfigurations:
        - ReplicationGroupId: test-redis-eu-west-2
          ReplicationGroupRegion: eu-west-2

Outputs:
  redisUrl:
    Description: URL for newly created redis service
    Value: !Ref RedisService

如果有人可以提供帮助,我收到此错误:

Properties validation failed for resource globalreplication with message: #/Members/0/Role: #: only 1 subschema matches out of 2 #/Members/0/Role: failed validation constraint for keyword [enum]

最佳答案

globalreplication:
Type: AWS::ElastiCache::GlobalReplicationGroup
DependsOn: RedisService
Properties:
  AutomaticFailoverEnabled: false
  GlobalReplicationGroupDescription: description example
  GlobalReplicationGroupIdSuffix: test
  Members:
    - ReplicationGroupId: !Ref ClusterName
      ReplicationGroupRegion: eu-west-1
      Role: PRIMARY

这将添加主节点并创建新的全局数据存储,然后需要在新创建的全局数据存储中添加辅助节点,您可以在此处看到前缀 https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Redis-Global-Datastores-CLI.html :

RedisService:
Type: AWS::ElastiCache::ReplicationGroup
Properties:
  CacheSubnetGroupName: !Ref RedisSubnetGroup
  ReplicationGroupId: !Ref ClusterName
  SecurityGroupIds:
    - !Ref ElasticacheComponentSecurityGroup
  GlobalReplicationGroupId: gxeiz-test
  ReplicationGroupDescription: Sample Redis group for scaling
  Port: 6379

关于amazon-web-services - AWS::ElastiCache::Global Replication Group 的 Cloudformation 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70498779/

相关文章:

aws-cloudformation - 从现有 AMI 快照创建 CloudFormation 堆栈

redis - 使用 Redis 集群自动故障转移到提升的 Redis Slave

kubernetes - Redis 集群客户端不适用于 GKE 上的 Redis 集群

amazon-web-services - 安装 Open JDK 和 SunJDK 并在启动应用程序时选择

mysql - 如何与其他团队成员共享MySQL数据库

json - AWS Cloudformation CLI 在将参数作为 json 文件传递​​时使用简写语法

go - 是否有一个 golang redis 客户端可以自动检测 pubsub 的新分片?

java - 将数据从 AWS Lambda 发送到 SQS 队列时连接重置

amazon-web-services - 我们的记录中不存在 AWS 访问 key ID

amazon-web-services - CDK Codepipeline CloudFormationCreateUpdateStackAction 仅在使用嵌套堆栈时获取 "S3: Access Denied"