@@ -8,6 +8,12 @@ def autoscaling(region: my_region)
88 @autoscaling_client [ region ] ||= Aws ::AutoScaling ::Client . new ( region : region )
99 end
1010
11+ def autoscaling_with_retries ( region : my_region )
12+ @autoscaling_client_with_retries ||= { }
13+ instance_credentials = Aws ::InstanceProfileCredentials . new ( retries : 5 , disable_imds_v1 : true )
14+ @autoscaling_client_with_retries [ region ] ||= Aws ::AutoScaling ::Client . new ( region : region , credentials : instance_credentials )
15+ end
16+
1117 def mark_me_as_unhealthy
1218 run_with_backoff do
1319 autoscaling . set_instance_health ( {
@@ -84,6 +90,30 @@ def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, li
8490 end
8591 end
8692
93+ def complete_lifecycle_action_with_retries ( lifecycle_hook_name :, auto_scaling_group_name :, lifecycle_action_token : nil , instance_id : nil )
94+ raise ArgumentError . new ( 'lifecycle_action_token or instance_id required' ) if lifecycle_action_token . nil? && instance_id . nil?
95+
96+ if lifecycle_action_token
97+ run_with_backoff do
98+ autoscaling_with_retries . complete_lifecycle_action ( {
99+ lifecycle_hook_name : lifecycle_hook_name ,
100+ auto_scaling_group_name : auto_scaling_group_name ,
101+ lifecycle_action_token : lifecycle_action_token ,
102+ lifecycle_action_result : 'CONTINUE'
103+ } )
104+ end
105+ else
106+ run_with_backoff do
107+ autoscaling_with_retries . complete_lifecycle_action ( {
108+ instance_id : instance_id ,
109+ lifecycle_hook_name : lifecycle_hook_name ,
110+ auto_scaling_group_name : auto_scaling_group_name ,
111+ lifecycle_action_result : 'CONTINUE'
112+ } )
113+ end
114+ end
115+ end
116+
87117 def record_lifecycle_action_heartbeat ( lifecycle_hook_name :, auto_scaling_group_name :, lifecycle_action_token : nil , instance_id : nil )
88118 raise ArgumentError . new ( 'lifecycle_action_token or instance_id required' ) if lifecycle_action_token . nil? && instance_id . nil?
89119
0 commit comments