At work, I made this script to “tail” CloudFormation events. The script is in Next Generation Shell, of which I am the author. Questions, comments, requests for improvements are welcome. Since it’s relatively small script, I’ll just post it here.
F epoch_time(s:Str) Time(s.split('.')[0] + '.000Z').Int() # NGS doesn't handle fractions of seconds yet
F main(stack_name:Str, interval:Int=2, start_limit=20, empty_line_seconds=60) {
last_seen = null
while true {
events = ``aws cloudformation describe-stack-events --stack-name $stack_name``.reverse()
start = if last_seen {
events.index(last_seen) + 1
} else {
max(len(events) - start_limit, 0)
}
new_events = events[start..null]
for e in new_events {
t = e.Timestamp.epoch_time()
if last_seen {
if t - last_seen.Timestamp.epoch_time() > empty_line_seconds {
echo("")
}
}
reason = ' ' +? e.get('ResourceStatusReason', '')
echo("${e.Timestamp} ${e.ResourceType.Str(50)} ${e.LogicalResourceId.Str(30)} ${e.ResourceStatus}${reason}")
last_seen = e
}
$(sleep $interval)
}
}
The script is on GitHub, in “NGS Scripts Dumpster” repository.