简体   繁体   English

Boto3 CloudTrail API 返回空响应

[英]Boto3 CloudTrail API returns empty response

I am running the following code and I can see CloudTrail events in the console and also comes in the cli ( that means I using the correct token ) but the response is empty.我正在运行以下代码,我可以在控制台中看到 CloudTrail 事件,也可以在 cli 中看到(这意味着我使用了正确的令牌),但响应为空。 What is the wrong in the code?代码有什么问题? Though I didn't need all regions but ran the code through all available to see if I can get response from any of the regions.虽然我不需要所有区域,但通过所有可用的代码运行代码以查看是否可以从任何区域获得响应。

This cli provides output aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventSource,AttributeValue=sts.amazonaws.com --max-items 10此 cli 提供 output aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventSource,AttributeValue=sts.amazonaws.com --max-items 10

But this code does not.但是这段代码没有。 The commented lines does not make any difference if uncomment them.如果取消注释,注释行没有任何区别。

import datetime
ec2_client = boto3.client('ec2')
response = ec2_client.describe_regions(AllRegions=True)
for reg in response['Regions']:
    print (reg['RegionName'])
    try:
        ct_client = boto3.client('cloudtrail', region_name=reg['RegionName'] )
        response = ct_client.lookup_events(
            LookupAttributes=[
                {
                    'AttributeKey': 'EventSource',
                    'AttributeValue': "sts.amazonaws.com"
                },
            ],
            # StartTime=datetime.datetime.now() - datetime.timedelta(minutes=10000),
            # EndTime=datetime.datetime.now(),
            EventCategory='insight',
            MaxResults=30,
        )
        print (response)
    except Exception as e:
        print (e)```

Resolved after removing EventCategory.删除 EventCategory 后解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM