-
Notifications
You must be signed in to change notification settings - Fork 11
/
cluster.yml
154 lines (145 loc) · 6.54 KB
/
cluster.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# stacks/shared-redis/cluster.yml
AWSTemplateFormatVersion: "2010-09-09"
Description: >-
Creates a Redis cluster intended to be used by several applications. The
cluster's security group will allow only traffic from a security group
provided as a stack parameter.
Parameters:
RootStackName: { Type: String }
RootStackId: { Type: String }
EnvironmentType: { Type: String }
EnvironmentTypeAbbreviation: { Type: String }
RegionMode: { Type: String }
NestedChangeSetScrubbingResourcesState: { Type: String }
VpcPrivateSubnet1Id: { Type: AWS::EC2::Subnet::Id }
VpcPrivateSubnet2Id: { Type: AWS::EC2::Subnet::Id }
VpcPrivateSubnet3Id: { Type: AWS::EC2::Subnet::Id }
CloudWatchAlarmTaggerServiceToken: { Type: String }
SharedRedisClusterSecurityGroupId: { Type: AWS::EC2::SecurityGroup::Id }
Conditions:
IsProduction: !Equals [!Ref EnvironmentType, Production]
IsPrimaryRegion: !Equals [!Ref RegionMode, Primary]
EnableNestedChangeSetScrubbingResources: !Equals [!Ref NestedChangeSetScrubbingResourcesState, Enabled]
Resources:
NestedChangeSetScrubber: { Type: AWS::SNS::Topic, Condition: EnableNestedChangeSetScrubbingResources }
RedisSubnetGroup:
Type: AWS::ElastiCache::SubnetGroup
Properties:
Description: !Sub Shared ${EnvironmentType} Redis subnet group
SubnetIds:
- !Ref VpcPrivateSubnet1Id
- !Ref VpcPrivateSubnet2Id
- !Ref VpcPrivateSubnet3Id
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:application, Value: Common }
RedisReplicationGroup:
Type: AWS::ElastiCache::ReplicationGroup
UpdatePolicy:
UseOnlineResharding: true
Properties:
AtRestEncryptionEnabled: false
AutomaticFailoverEnabled: true
AutoMinorVersionUpgrade: false
CacheNodeType: !If [IsProduction, !If [IsPrimaryRegion, cache.m6g.large, cache.t4g.medium], cache.t4g.small]
CacheParameterGroupName: default.redis7.cluster.on
CacheSubnetGroupName: !Ref RedisSubnetGroup
Engine: Redis
EngineVersion: 7.1
MultiAZEnabled: true
NumNodeGroups: 1 # NodeGroups are Shards. This replication group will always use cluster mode due to the parameter group.
ReplicasPerNodeGroup: 1 # **Update requires replacement** Replicas are nodes. N replicas will result in N+1 Nodes Per Shard.
ReplicationGroupDescription: !Sub Dovetail ${EnvironmentType} Redis
SecurityGroupIds:
- !Ref SharedRedisClusterSecurityGroupId
SnapshotRetentionLimit: 0 # 0 = automatic backups are disabled
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:application, Value: Common }
RedisMemoryLowAlarm:
Type: AWS::CloudWatch::Alarm
Condition: IsProduction
Properties:
AlarmName: !Sub WARN [Common] Redis <${EnvironmentTypeAbbreviation}> HIGH MEMORY USAGE
AlarmDescription: !Sub >-
${EnvironmentType} shared Redis's database memory usage has exceeded
the recommended safe level
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: CacheClusterId
Value: !Ref RedisReplicationGroup
EvaluationPeriods: 2
MetricName: DatabaseMemoryUsagePercentage
Namespace: AWS/ElastiCache
Period: 120
Statistic: Maximum
Threshold: 0.85
TreatMissingData: notBreaching
Unit: Percent
RedisMemoryLowAlarmTags:
Type: Custom::CloudWatchAlarmTags
Condition: IsProduction
Properties:
ServiceToken: !Ref CloudWatchAlarmTaggerServiceToken
AlarmArn: !GetAtt RedisMemoryLowAlarm.Arn
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:application, Value: Common }
RedisMemoryVeryLowAlarm:
Type: AWS::CloudWatch::Alarm
Condition: IsProduction
Properties:
AlarmName: !Sub ERROR [Common] Redis <${EnvironmentTypeAbbreviation}> VERY HIGH MEMORY USAGE
AlarmDescription: !Sub >-
${EnvironmentType} shared Redis's database memory usage has reached a
critically high level
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: CacheClusterId
Value: !Ref RedisReplicationGroup
EvaluationPeriods: 2
MetricName: DatabaseMemoryUsagePercentage
Namespace: AWS/ElastiCache
Period: 120
Statistic: Maximum
Threshold: 0.93
TreatMissingData: notBreaching
Unit: Percent
RedisMemoryVeryLowAlarmTags:
Type: Custom::CloudWatchAlarmTags
Condition: IsProduction
Properties:
ServiceToken: !Ref CloudWatchAlarmTaggerServiceToken
AlarmArn: !GetAtt RedisMemoryVeryLowAlarm.Arn
Tags:
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }
- { Key: prx:cloudformation:stack-id, Value: !Ref AWS::StackId }
- { Key: prx:cloudformation:root-stack-name, Value: !Ref RootStackName }
- { Key: prx:cloudformation:root-stack-id, Value: !Ref RootStackId }
- { Key: prx:ops:environment, Value: !Ref EnvironmentType }
- { Key: prx:dev:application, Value: Common }
Outputs:
ReplicationGroupName:
Value: !Ref RedisReplicationGroup
ReplicationGroupEndpointAddress:
Description: Cluster endpoint hostname
Value: !GetAtt RedisReplicationGroup.ConfigurationEndPoint.Address
ReplicationGroupEndpointPort:
Description: Cluster endpoint port
Value: !GetAtt RedisReplicationGroup.ConfigurationEndPoint.Port