Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit cdca378

Browse files
committed
#150 print CF status reasons when "senza wait" fails
1 parent c79c85f commit cdca378

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

senza/cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from subprocess import call
1717

1818
import 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
2020
from clickclick.console import print_table
2121
import requests
2222
import 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

Comments
 (0)