Skip to content

Commit

Permalink
add delay before handling autoscaling events
Browse files Browse the repository at this point in the history
  • Loading branch information
Szpadel committed May 22, 2024
1 parent b199d94 commit 5f0ea3c
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions handle_autoscaling_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import boto3
import os
import json
import time

LIFECYCLE_ACTION_CONTINUE = 'CONTINUE'
LIFECYCLE_ACTION_ABANDON = 'ABANDON'
Expand Down Expand Up @@ -128,6 +129,10 @@ def handle_lifecycle_event(event_type, event_data):

print('Handling lifecycle event "%s" / hook "%s"' % (event_type, current_hook))

# Wait 5s before continuing to allow aws to propagate instance statuses
# In some cases when we query instances we receive outdated statuses from before received event
time.sleep(5)

if current_hook == terminate_hook:
update_backends([instance_id], True)
complete_lifecycle_action(current_hook, asg_name, instance_id, LIFECYCLE_ACTION_CONTINUE)
Expand All @@ -150,24 +155,3 @@ def handle(event, context):
handle_plain_event(event_type, event_data)

return "All good"





















0 comments on commit 5f0ea3c

Please sign in to comment.