Skip to content

Instantly share code, notes, and snippets.

@angrychimp
Last active February 27, 2018 06:59
Show Gist options
  • Select an option

  • Save angrychimp/3f1582ccc4b2ef11f8b2d671a71626b6 to your computer and use it in GitHub Desktop.

Select an option

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]`
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()
@rajasekhar09
Copy link

Tnqs Angrychimp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment