If you make various trials and errors with CloudFormation, it will be awkward to click from the mannequin, and you will want to create-stack or delete-stack with CLI. However, it is troublesome to hit the command one by one to read JSON, and it is also troublesome to just look at the mannequin and hit the load button, so I created it quickly. I like how easy it is for python to write this within 30 steps ...
Since boto3 and tabulate are not included as standard, `pip install`
should be done.
For boto3, refer to the Around site.
import os
import sys
import time
import boto3
import pprint
from tabulate import tabulate
args = sys.argv
client = boto3.client('cloudformation')
stackstatus = ""
while stackstatus != 'CREATE_COMPLETE':
os.system('clear')
response = client.describe_stacks(StackName=args[1])
stacks = response['Stacks']
stackstatus = stacks[0]['StackStatus']
response = client.describe_stack_events(StackName=args[1])
events = response['StackEvents']
events.sort(key=lambda x:x['Timestamp'])
rows = []
for keys in events:
cols = []
cols.append(keys['Timestamp'])
cols.append(keys['LogicalResourceId'])
cols.append(keys['ResourceStatus'])
rows.append(cols)
headers = ['Timestamp', 'LogicalResourceId', 'Status']
table = tabulate(rows, headers)
print(table)
if stackstatus != 'CREATE_COMPLETE':
time.sleep(10)
When I run it, ↓ This screen is ...
This is it! On the console, when a new record comes up, it will flow, so the display is reversed.
Timestamp LogicalResourceId Status
-------------------------------- -------------------------- ------------------
2020-05-10 10:47:57.928000+00:00 ApigwTest-issue01-Pipeline CREATE_IN_PROGRESS
2020-05-10 10:48:02.269000+00:00 CODEBUILDLOGGROUP CREATE_IN_PROGRESS
2020-05-10 10:48:02.699000+00:00 S3BUCKET CREATE_IN_PROGRESS
2020-05-10 10:48:02.789000+00:00 CODEBUILDLOGGROUP CREATE_IN_PROGRESS
2020-05-10 10:48:03.178000+00:00 CODEBUILDLOGGROUP CREATE_COMPLETE
2020-05-10 10:48:04.363000+00:00 S3BUCKET CREATE_IN_PROGRESS
2020-05-10 10:48:25.539000+00:00 S3BUCKET CREATE_COMPLETE
2020-05-10 10:48:27.772000+00:00 CODEBUILDIAMROLE CREATE_IN_PROGRESS
2020-05-10 10:48:29.158000+00:00 CODEBUILDIAMROLE CREATE_IN_PROGRESS
2020-05-10 10:48:45.746000+00:00 CODEBUILDIAMROLE CREATE_COMPLETE
2020-05-10 10:48:49.115000+00:00 CODEBUILD CREATE_IN_PROGRESS
2020-05-10 10:48:51.445000+00:00 CODEBUILD CREATE_IN_PROGRESS
2020-05-10 10:48:52.222000+00:00 CODEBUILD CREATE_COMPLETE
2020-05-10 10:48:54.622000+00:00 PIPELINE CREATE_IN_PROGRESS
2020-05-10 10:48:55.360000+00:00 PIPELINE CREATE_IN_PROGRESS
2020-05-10 10:48:55.853000+00:00 PIPELINE CREATE_COMPLETE
2020-05-10 10:48:57.646000+00:00 ApigwTest-issue01-Pipeline CREATE_COMPLETE
Recommended Posts