【问题标题】:Cloud Formation template for AWS::ElastiCache::GlobalReplicationGroupAWS::ElastiCache::Global Replication Group 的 Cloudformation 模板
【发布时间】:2022-01-26 14:43:01
【问题描述】:

想要使用 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

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

资源全局复制的属性验证失败,消息为:#/Members/0/Role:#: 2 个子模式中只有 1 个匹配 #/Members/0/Role:关键字 [enum] 的验证约束失败

【问题讨论】:

  • rglobalreplication.Properties.Members 的第一个成员有一个Role,但第二个成员有。 docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… 是每个成员项目的文档。也许secondary 应该是Role 的值,而不是ReplicationGroupId?
  • @DanielFarrell 我将 RegionConfigurations 中的 ReplicationGroupId 更改为 test-redis-eu-west-2 ,只是为了检查这一点,但仍然收到相同的错误 Properties validation failed for resource globalreplication with message: #/Members /0/Role: #: 2 个子模式中只有 1 个匹配 #/Members/0/Role: 关键字 [enum] 的验证约束失败,如果我完全删除 Role,它会给我错误: GlobalReplicationGroup 需要主要成员跨度>
  • 您不需要从第一个成员中删除角色,您需要将其添加到第二个成员。
  • @DanielFarrell:是的,我也试过了,这是我得到的错误:资源 globalreplication 的属性验证失败,消息为:#/RegionalConfigurations/0: extraneous key [Role] is not allowed #/ Members/0/Role: #: 2 个子模式中只有 1 个匹配 #/Members/0/Role: 关键字 [enum] 的验证约束失败

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


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2015-12-08
    • 2021-09-02
    • 2021-07-20
    • 2016-12-12
    • 2018-05-04
    • 1970-01-01
    • 2020-11-01
    • 2017-06-25
    • 2018-10-12
    相关资源
    最近更新 更多