How do I find who created a CloudFormation stack?
I am using boto3
to list the stacks whose status is COMPLETE
along with the user who created the stack. I can get all the attributes of the stack but I am unable to find the user information in CloudFormation dashboard or in boto3 CF APIs. Any idea how to get the IAM username of the user that created the stack?
Thanks
Snippet of my code:
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']
...
...
You can get this information through CloudTrail. In particular, call lookup_events()
on the CloudTrail client:
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With