0

wanted to create Redis global datastore using CF , following the guidelines https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticache-globalreplicationgroup.html

but no luck, I can create Redis cluster but not the global data store : My code:

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

if any one can help , I am getting This error:

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]

Nitish
  • 47
  • 4
  • The first member of `rglobalreplication.Properties.Members` has a `Role`, but the second one does. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticache-globalreplicationgroup-globalreplicationgroupmember.html is the documentation for each of those member items. Maybe `secondary` was supposed to be the value of `Role`, not `ReplicationGroupId`? – erik258 Dec 27 '21 at 17:54
  • @DanielFarrell I Changed the ReplicationGroupId in RegionalConfigurations to test-redis-eu-west-2 , just to check this point , but still getting same error 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] , if I remove Role altogether it gives me error : Primary member is required for a GlobalReplicationGroup – Nitish Dec 27 '21 at 18:12
  • You don't need to *remove* Role from the first member, you need to *add* it to the second. – erik258 Dec 27 '21 at 18:13
  • @DanielFarrell: Yes I tried that as well , this is the error I got :Properties validation failed for resource globalreplication with message: #/RegionalConfigurations/0: extraneous key [Role] is not permitted #/Members/0/Role: #: only 1 subschema matches out of 2 #/Members/0/Role: failed validation constraint for keyword [enum] – Nitish Dec 27 '21 at 18:22

1 Answers1

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

This will add the primary node and create new global data store and then need to add the secondary node in the newly created global data store , you can see the prefixes here 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
Nitish
  • 47
  • 4