我试图通过boto3从cloudtrail获取实例id的事件,如(runinstances、createtags和terminateinstances),下面是我的代码
import boto3
cloudtrail = boto3.client('cloudtrail')
instance_id = 'i-0002e660b987688'
starttime = '2020-04-01'
endtime = '2020-04-03'
try:
response = cloudtrail.lookup_events(
LookupAttributes=[
{
'AttributeKey': 'ResourceName',
'AttributeValue': instance_id
},
],
StartTime=starttime,
EndTime=endtime,
MaxResults=50
)
except Exception as e:
print(e)
raise(e)
print(response)
我没有得到任何事件,从AWS控制台我可以看到上面指定的时间段内的所有事件
{u'Events': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': '658e4873-b0d1-453c', 'HTTPHeaders': {'x-amzn-requestid': '658e4873-b0d1-453', 'date': 'Fri, 03 Apr 2020 03:53:57 GMT', 'content-length': '13', 'content-type': 'application/x-amz-json-1.1'}}}
似乎删除endtime对我有效,但不知道为什么
我现在可以得到想要的活动了
相关问题 更多 >
编程相关推荐