2017-11-11 215 views
1

我使用下面的代碼,但沒有得到所需的事件詳細信息。我確認事件ID是正確的,並檢查從aws UI返回的詳細信息lookup_events使用boto3不返回事件詳細信息

我也試過在事件ID之前和之後沒有單引號,但沒有返回細節。

client = boto3.client('cloudtrail',region_name='us-east-1') 
     response = client.lookup_events(
      LookupAttributes=[ 
       { 
        'AttributeKey': 'EventId', 
        'AttributeValue': "'" + str(eventid) + "'" 
       }, 
      ], 

      MaxResults=1, 

     ) 

下面是我收到的回覆,事件是空的。

{u'Events': [], 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'ea8888ab-0987-1234-4321-096c31sdfsdf', 'HTTPHeaders': {'x-amzn-requestid': '345551dd-1234-9876-1221-sddweerwer', 'date': 'Sat, 11 Nov 2017 17:08:20 GMT', 'content-length': '13', 'content-type': 'application/x-amz-json-1.1'}}} 

回答

0

的屬性嘗試

LookupAttributes=[ 
    { 
     'AttributeKey': 'EventId', 
     'AttributeValue': "{}".format(eventid) 
    }, 
] 

如果不是這樣,也許三重檢查eventid定義?

+0

此解決方案適合我!謝謝 !! – dip

0

請勿在EventId中加引號。只有在通過Python傳遞原始值時才需要引號 - 實際值不應包含引號。

'AttributeValue': eventid