Skip to content

Commit

Permalink
Merge pull request #1 from BEvgeniyS/support-complete
Browse files Browse the repository at this point in the history
show last events even if stack status is _COMPLETE
  • Loading branch information
BEvgeniyS authored Mar 11, 2024
2 parents 6961a6f + b3023a3 commit c362750
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cfn_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_sorted_cfn_stack_events(stack, latest_event=None, initial_events=10, con
help="Don't stop after stack has reached *_COMPLETED state", default=False)
args = parser.parse_args()

initial_events=args.initial_events
initial_events=int(args.initial_events)
continuous=args.continuous
stack_name=args.stack_name
client = boto3.client('cloudformation')
Expand All @@ -40,23 +40,25 @@ def get_sorted_cfn_stack_events(stack, latest_event=None, initial_events=10, con

print (f'Tailing {stack_name}')


while continuous or stack.stack_status.endswith('_IN_PROGRESS'):
while continuous or stack.stack_status.endswith('_IN_PROGRESS') or initial_events > 0:
evts, latest_event = get_sorted_cfn_stack_events(stack, latest_event, initial_events)
for evt in evts:
status_reason = '' if evt.resource_status_reason is None else str(evt.resource_status_reason)
print(f'{evt.timestamp:%Y-%m-%d %H:%M:%S%z} [{evt.logical_resource_id}] {evt.resource_status} {status_reason}')
evts = None
initial_events = 0
stack.load()
sleep(3)

if not continuous:
# Statuses list:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
# Stack update failed
if stack.stack_status.endswith('ROLLBACK_COMPLETE'):
sys.exit(1)
# Stack create/update succeeded
elif stack.stack_status.endswith('_COMPLETE'):
elif stack.stack_status in ['CREATE_COMPLETE', 'DELETE_COMPLETE', 'UPDATE_COMPLETE', 'IMPORT_COMPLETE']:
sys.exit(0)
# Stack final state is unknown
else:
sys.exit(1)
sys.exit(1)

0 comments on commit c362750

Please sign in to comment.