Module: MovableInk::AWS::ElastiCache

Included in:
MovableInk::AWS
Defined in:
lib/movable_ink/aws/elasticache.rb

Instance Method Summary collapse

Instance Method Details

#all_elasticache_replicas(role) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/movable_ink/aws/elasticache.rb', line 22

def all_elasticache_replicas(role)
  replication_group(role).node_groups
                         .first
                         .node_group_members
                         .select{|ng| ng.current_role == 'replica'}
                         .map{|member| member.read_endpoint.address}
end

#elasticache(region: my_region) ⇒ Object



4
5
6
7
# File 'lib/movable_ink/aws/elasticache.rb', line 4

def elasticache(region: my_region)
  @elasticache_client ||= {}
  @elasticache_client[region] ||= Aws::ElastiCache::Client.new(region: region)
end

#elasticache_primary(role) ⇒ Object



15
16
17
18
19
20
# File 'lib/movable_ink/aws/elasticache.rb', line 15

def elasticache_primary(role)
  replication_group(role).node_groups
                         .first
                         .primary_endpoint
                         .address
end

#elasticache_replica_in_my_az(role) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/movable_ink/aws/elasticache.rb', line 30

def elasticache_replica_in_my_az(role)
  members = replication_group(role).node_groups
                                   .first
                                   .node_group_members
                                   .select{|ng| ng.preferred_availability_zone == availability_zone}
  begin
    members.select{|ng| ng.current_role == 'replica'}
    .first
    .read_endpoint
    .address
  rescue NoMethodError
    members.first
           .read_endpoint
           .address
  end
end

#replication_group(role) ⇒ Object



9
10
11
12
13
# File 'lib/movable_ink/aws/elasticache.rb', line 9

def replication_group(role)
  run_with_backoff do
    @replication_group ||= elasticache.describe_replication_groups({replication_group_id: "#{mi_env}-#{role}"}).replication_groups.first
  end
end