import boto3
from botocore.exceptions import ClientError
import json
client = boto3.client('cloudformation')
try:
response = client.describe_stack_events(
StackName='myStack',
NextToken='string'
)
except ClientError as e:
print(e)
其中,StackName参数用于指定堆栈名称,NextToken参数可选,用于指定下一个套接字事件批次的令牌。
events = response['StackEvents']
for event in events:
print("EventId: {}".format(event['EventId']))
print("EventTime: {}".format(event['Timestamp']))
print("EventName: {}".format(event['ResourceStatus']))
print("LogicalResourceId: {}".format(event['LogicalResourceId']))
print("ResourceType: {}".format(event['ResourceType']))
print("ResourceStatus: {}".format(event['ResourceStatus']))
print()
该代码将输出每个事件的唯一标识符、时间戳、资源状态、逻辑资源ID和资源类型。