Skip to content

Commit bc447dc

Browse files
committed
added rules
1 parent 8a6782a commit bc447dc

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

managed-gdb-cft.yml

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,30 @@ Resources:
131131
# skip if the endpoint is not active
132132
elif (j['EndpointType']=="WRITER" and j['Status']=='inactive'):
133133
print("This is a writer enpoint of a secondary region, skipping")
134-
134+
135+
136+
# If this was a detach-promote event, we consider this as a unplanned failover and delete the ddb entry.
137+
if eventid == "RDS-EVENT-0228":
138+
print("Removing entry for cluster",cluname,"from the dynamodb table")
139+
dresponse = ddbclient.delete_item(
140+
TableName='gdbcnamepair',
141+
Key = {
142+
'clustername':{'S':cluname}
143+
}
144+
)
145+
135146
return {
136147
'statusCode': 200,
137148
'body': json.dumps('event processed')
138149
}
150+
139151
else:
140152
return {
141153
'statusCode': 100,
142154
'body': json.dumps('event discarded!')
155+
}
156+
143157
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-
153-
}
154158
else:
155159
print("Cluster entry not found int the table. Event discarded.")
156160
@@ -159,7 +163,7 @@ Resources:
159163
Type: AWS::Events::Rule
160164
DependsOn: gdbmanagedeplambda
161165
Properties:
162-
Description: Event Bridge rule to track Aurora global database failover in this region
166+
Description: Event Bridge rule to track Aurora Global Database failover in this region
163167
EventPattern:
164168
source:
165169
- "aws.rds"
@@ -176,11 +180,11 @@ Resources:
176180
Id: "gdblambdatarget"
177181

178182
#Create the eventbridge rule. This rule triggers when a cluster is removed from a global database (detach-promote).
179-
gdbmanagedepeventbrule:
183+
gdbmanagedepupeventbrule:
180184
Type: AWS::Events::Rule
181185
DependsOn: gdbmanagedeplambda
182186
Properties:
183-
Description: Event Bridge rule to track Aurora global database failover in this region
187+
Description: Event Bridge rule to track Aurora Global Database detach and promote event (unplanned failover)
184188
EventPattern:
185189
source:
186190
- "aws.rds"
@@ -206,6 +210,15 @@ Resources:
206210
Principal: events.amazonaws.com
207211
SourceArn: !GetAtt gdbmanagedepeventbrule.Arn
208212

213+
gdbmanagedepuplambdapermission:
214+
Type: AWS::Lambda::Permission
215+
DependsOn: gdbmanagedepupeventbrule
216+
Properties:
217+
Action: lambda:InvokeFunction
218+
FunctionName: !GetAtt gdbmanagedeplambda.Arn
219+
Principal: events.amazonaws.com
220+
SourceArn: !GetAtt gdbmanagedepupeventbrule.Arn
221+
209222
#Create the role needed for the lambda function.
210223
gdbmanagedeprole:
211224
Type: 'AWS::IAM::Role'
@@ -333,10 +346,11 @@ Resources:
333346
Version: 2012-10-17
334347
Statement:
335348
Effect: Allow
336-
Action: dynamodb:GetItem
337-
Action: dynamodb:PutItem
338-
Action: dynamodb:DeleteItem
339-
Action: dynamodb:UpdateItem
349+
Action:
350+
- dynamodb:GetItem
351+
- dynamodb:PutItem
352+
- dynamodb:DeleteItem
353+
- dynamodb:UpdateItem
340354
Resource: !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${gdbmanagedepddbtbl}"
341355
ManagedPolicyName:
342356
Fn::Join:

0 commit comments

Comments
 (0)