Last active
February 27, 2018 06:59
-
-
Save angrychimp/3f1582ccc4b2ef11f8b2d671a71626b6 to your computer and use it in GitHub Desktop.
Gets the status of a CloudFormation stack and refreshes until a terminal state is reached. Run from command line using `python get-cf-status.py [stack-name-or-id]`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print | |
| import boto3 | |
| import datetime | |
| import sys | |
| def main(): | |
| client = boto3.client('cloudformation') | |
| stack_name = sys.argv[1] | |
| stack = client.describe_stacks(StackName=stack_name)['Stacks'][0] | |
| # refresh while state is not final | |
| while (stack['StackStatus'].split('_')[-1] not in ['FAILED', 'SKIPPED', 'COMPLETE']): | |
| reason = "Complete" | |
| if 'StackStatusReason' in stack: | |
| reason = stack['StackStatusReason'] | |
| print("\r[%s] %s: %s" % (datetime.datetime.now().strftime('%H:%M:%S'), stack['StackStatus'], reason)) | |
| reason = "Complete" | |
| if 'StackStatusReason' in stack: | |
| reason = stack['StackStatusReason'] | |
| print("\r[%s] %s: %s (%s)" % (datetime.datetime.now().strftime('%H:%M:%S'), stack['StackStatus'], reason, stack['LastUpdatedTime'].strftime('%Y-%m-%d-%H:%M:%S'))) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tnqs Angrychimp