Skip to content

Commit 4416585

Browse files
authored
Delete schedules after execution (#130)
When access is granted, an EventBridgeSchedule is created to fire when access should be revoked. However the schedules are not deleted, and so the list of schedules continues to grow, for ever. This has the knock-on effect of making the revoke lambda run slower and slower, as it has to paginate through more and more old schedules. This commit sets the ActionAfterCompletion property on the schedule so that once it has executed AWS will delete it. This means that the number of schedules should remain fairly constant over a given period of time. Note that I have not included anything here to delete old schedules, so tidying-up an existing installation will be something that each team will need to perform manually. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Sets ActionAfterCompletion=DELETE on all created EventBridge schedules so they are removed after firing. > > - **Scheduler**: > - Set `ActionAfterCompletion` to `DELETE` for schedules created in: > - `schedule_revoke_event` > - `schedule_group_revoke_event` > - `schedule_discard_buttons_event` > - `schedule_approver_notification_event` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit be0f8c1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 437445f commit 4416585

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/schedule.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def schedule_revoke_event(
150150
)
151151
logger.debug("Creating schedule", extra={"revoke_event": revoke_event})
152152
return schedule_client.create_schedule(
153+
ActionAfterCompletion="DELETE",
153154
FlexibleTimeWindow={"Mode": "OFF"},
154155
Name=schedule_name,
155156
GroupName=cfg.schedule_group_name,
@@ -187,6 +188,7 @@ def schedule_group_revoke_event(
187188
get_and_delete_scheduled_revoke_event_if_already_exist(schedule_client, group_assignment)
188189
logger.debug("Creating schedule", extra={"revoke_event": revoke_event})
189190
return schedule_client.create_schedule(
191+
ActionAfterCompletion="DELETE",
190192
FlexibleTimeWindow={"Mode": "OFF"},
191193
Name=schedule_name,
192194
GroupName=cfg.schedule_group_name,
@@ -227,6 +229,7 @@ def schedule_discard_buttons_event(
227229
},
228230
)
229231
return schedule_client.create_schedule(
232+
ActionAfterCompletion="DELETE",
230233
FlexibleTimeWindow={"Mode": "OFF"},
231234
Name=schedule_name,
232235
GroupName=cfg.schedule_group_name,
@@ -270,6 +273,7 @@ def schedule_approver_notification_event(
270273
},
271274
)
272275
return schedule_client.create_schedule(
276+
ActionAfterCompletion="DELETE",
273277
FlexibleTimeWindow={"Mode": "OFF"},
274278
Name=schedule_name,
275279
GroupName=cfg.schedule_group_name,

0 commit comments

Comments
 (0)