Skip to content

Commit 8a6782a

Browse files
committed
Modified Lambda and added new event for tracking unplanned failover
1 parent f3dfd9b commit 8a6782a

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

managed-gdb-cft.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Resources:
8484
hzID=dresponse['Item']['hostedzoneid']['S']
8585
8686
# Only process event if the the global database failover completed
87-
if eventid == "RDS-EVENT-0185":
87+
if eventid == "RDS-EVENT-0185" or eventid == "RDS-EVENT-0228":
8888
print("Message is: ",mymsg)
8989
print("Event Id is: ", eventid)
9090
print("Region is ",regioname)
@@ -140,11 +140,21 @@ Resources:
140140
return {
141141
'statusCode': 100,
142142
'body': json.dumps('event discarded!')
143+
144+
# If this was a detach-promote event, we consider this as a unplanned failover and delete the ddb entry.
145+
if eventid == "RDS-EVENT-0228":
146+
dresponse = ddbclient.delete_item(
147+
TableName='gdbcnamepair',
148+
Key = {
149+
'clustername':{'S':cluname}
150+
}
151+
)
152+
143153
}
144154
else:
145155
print("Cluster entry not found int the table. Event discarded.")
146156
147-
#Create the eventbridge rule. This rule triggers everything a global database completes failover.
157+
#Create the eventbridge rule. This rule triggers when a global database completes failover.
148158
gdbmanagedepeventbrule:
149159
Type: AWS::Events::Rule
150160
DependsOn: gdbmanagedeplambda
@@ -165,6 +175,26 @@ Resources:
165175
- Arn: !GetAtt gdbmanagedeplambda.Arn
166176
Id: "gdblambdatarget"
167177

178+
#Create the eventbridge rule. This rule triggers when a cluster is removed from a global database (detach-promote).
179+
gdbmanagedepeventbrule:
180+
Type: AWS::Events::Rule
181+
DependsOn: gdbmanagedeplambda
182+
Properties:
183+
Description: Event Bridge rule to track Aurora global database failover in this region
184+
EventPattern:
185+
source:
186+
- "aws.rds"
187+
detail-type:
188+
- "RDS DB Cluster Event"
189+
detail:
190+
EventCategories:
191+
- "configuration change"
192+
EventID:
193+
- "RDS-EVENT-0228"
194+
Name: AuroraGDBUnplannedfailovertracking
195+
Targets:
196+
- Arn: !GetAtt gdbmanagedeplambda.Arn
197+
Id: "gdblambdatarget"
168198

169199
#Add the lambda permission so it can be invoked by the rule
170200
gdbmanagedeplambdapermission:
@@ -304,6 +334,9 @@ Resources:
304334
Statement:
305335
Effect: Allow
306336
Action: dynamodb:GetItem
337+
Action: dynamodb:PutItem
338+
Action: dynamodb:DeleteItem
339+
Action: dynamodb:UpdateItem
307340
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${gdbmanagedepddbtbl}"
308341
ManagedPolicyName:
309342
Fn::Join:

0 commit comments

Comments
 (0)