1616from subprocess import call
1717
1818import click
19- from clickclick import AliasedGroup , Action , choice , info , FloatRange , OutputFormat , fatal_error , ok
19+ from clickclick import AliasedGroup , Action , choice , info , FloatRange , OutputFormat , error , fatal_error , ok
2020from clickclick .console import print_table
2121import requests
2222import yaml
@@ -1315,6 +1315,11 @@ def scale(stack_ref, region, desired_capacity):
13151315 ** kwargs )
13161316
13171317
1318+ def failure_event (event : dict ):
1319+ status = event .get ('ResourceStatus' )
1320+ return event .get ('ResourceStatusReason' ) and ('FAIL' in status or 'ROLLBACK' in status )
1321+
1322+
13181323@cli .command ()
13191324@click .argument ('stack_ref' , nargs = - 1 )
13201325@click .option ('-d' , '--deletion' , is_flag = True , help = 'Wait for deletion instead of CREATE_COMPLETE' )
@@ -1328,7 +1333,7 @@ def wait(stack_ref, region, deletion, timeout):
13281333
13291334 stack_refs = get_stack_refs (stack_ref )
13301335 region = get_region (region )
1331- check_credentials ( region )
1336+ cf = boto3 . client ( 'cloudformation' , region )
13321337
13331338 cutoff = time .time () + timeout
13341339 target_status = 'DELETE_COMPLETE' if deletion else 'CREATE_COMPLETE'
@@ -1340,6 +1345,12 @@ def wait(stack_ref, region, deletion, timeout):
13401345 if stack .StackStatus == target_status :
13411346 stacks_ok .add ((stack .name , stack .version ))
13421347 elif stack .StackStatus .endswith ('_FAILED' ) or stack .StackStatus .endswith ('_COMPLETE' ):
1348+ # output event messages for troubleshooting
1349+ events = cf .describe_stack_events (StackName = stack .StackId )['StackEvents' ]
1350+
1351+ for event in sorted (events , key = lambda x : x ['Timestamp' ]):
1352+ if failure_event (event ):
1353+ error ('ERROR: {LogicalResourceId} {ResourceStatus}: {ResourceStatusReason}' .format (** event ))
13431354 fatal_error ('ERROR: Stack {}-{} has status {}' .format (stack .name , stack .version , stack .StackStatus ))
13441355 else :
13451356 stacks_nok .add ((stack .name , stack .version , stack .StackStatus ))
0 commit comments