-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckout.py
More file actions
38 lines (30 loc) · 1.09 KB
/
checkout.py
File metadata and controls
38 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import time
import sys
import boto3
def main(args):
asg_name = os.environ.get('ASG_NAME')
assert asg_name is not None, 'Must set ASG_NAME in environment.'
autoscaling = boto3.client('autoscaling')
try:
refresh = autoscaling.describe_instance_refreshes(
AutoScalingGroupName=asg_name,
MaxRecords=1
)['InstanceRefreshes'][0]
except KeyError:
print('Trigger at least one Instance Refresh first.')
sys.exit(os.EX_UNAVAILABLE)
while refresh['Status'] not in ['Successful', 'Failed', 'Cancelled']:
print(
f"Instance Refresh {refresh['Status']} "
f"[{refresh.get('PercentageComplete', 0)}%]: "
f"{refresh.get('StatusReason', '')}"
)
time.sleep(5)
refresh = autoscaling.describe_instance_refreshes(
AutoScalingGroupName=asg_name,
InstanceRefreshIds=[refresh['InstanceRefreshId']]
)['InstanceRefreshes'][0]
print(f"Instance Refresh {refresh['Status']} at {refresh['EndTime']}")
if __name__ == '__main__':
main(args=[])