gpt4 book ai didi

amazon-web-services - 如何找到 CloudFormation 堆栈的创建者?

转载 作者:行者123 更新时间:2023-12-03 20:34:05 25 4
gpt4 key购买 nike

如何找到 CloudFormation 堆栈的创建者?

我使用 boto3 列出状态为 COMPLETE 的堆栈以及创建该堆栈的用户。我可以获得堆栈的所有属性,但无法在 CloudFormation 仪表板或 boto3 CF API 中找到用户信息。知道如何获取创建堆栈的用户的 IAM 用户名吗?

谢谢

我的代码片段:

import boto3

cf = boto3.client('cloudformation', region_name='us-east-1')
stacks = cf.list_stacks(StackStatusFilter=['CREATE_COMPLETE'])['StackSummaries']
names = [stack['StackName'] for stack in stacks]

for name in names:
resources = cf.describe_stack_resources(StackName=name)['StackResources']
...
...

最佳答案

您可以通过 CloudTrail 获取此信息。特别是,在 CloudTrail 客户端上调用 lookup_events():

events = cloudtrail_client.lookup_events(LookupAttributes=[{'AttributeKey':'EventName', 'AttributeValue':'CreateStack'}])
for event in events['Events']:
event_detail = json.loads(event['CloudTrailEvent'])
if event_detail['requestParameters']['stackName'] == myStackName:
creator = event['Username']

关于amazon-web-services - 如何找到 CloudFormation 堆栈的创建者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36485632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com