谁使用Boto和Python创建了Amazon EC2实例? [英] Who created an Amazon EC2 instance using Boto and Python?
本文介绍了谁使用Boto和Python创建了Amazon EC2实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道谁创建了一个特定的实例。我正在使用Cloud Trail来查找统计信息,但无法获得有关谁创建了该实例的特定统计信息。我正在使用Python和Boto3来查找详细信息。
我在boto3的Cloud Trail中使用此代码-Lookup events()来提取有关实例的信息。
I want to know who created a particular instance. I am using Cloud Trail to find out the statistics, but I am not able to get a particular statistics of who created that instance. I am using Python and Boto3 for finding out the details. I am using this code- Lookup events() from Cloud trail in boto3, to extract the information about an instance.
ct_conn = sess.client(service_name='cloudtrail',region_name='us-east-1')
events=ct_conn.lookup_events()
推荐答案
我使用lookup_events()函数找到了上述问题的解决方案。
I found out the solution to the above problem using lookup_events() function.
ct_conn = boto3.client(service_name='cloudtrail',region_name='us-east-1')
events_dict= ct_conn.lookup_events(LookupAttributes=[{'AttributeKey':'ResourceName', 'AttributeValue':'i-xxxxxx'}])
for data in events_dict['Events']:
json_file= json.loads(data['CloudTrailEvent'])
print json_file['userIdentity']['userName']
这篇关于谁使用Boto和Python创建了Amazon EC2实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文