選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

LookupEvents 搭配 AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

LookupEvents 搭配 AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 LookupEvents

C++
SDK for C++
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Routine which looks up events captured by AWS CloudTrail. /*! \param clientConfig: Aws client configuration. \return bool: Function succeeded. */ bool AwsDoc::CloudTrail::lookupEvents( const Aws::Client::ClientConfiguration &clientConfig) { Aws::CloudTrail::CloudTrailClient cloudtrail(clientConfig); Aws::String nextToken; // Used for pagination. Aws::Vector<Aws::CloudTrail::Model::Event> allEvents; Aws::CloudTrail::Model::LookupEventsRequest request; size_t count = 0; do { if (!nextToken.empty()) { request.SetNextToken(nextToken); } Aws::CloudTrail::Model::LookupEventsOutcome outcome = cloudtrail.LookupEvents( request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::CloudTrail::Model::Event> &events = outcome.GetResult().GetEvents(); count += events.size(); allEvents.insert(allEvents.end(), events.begin(), events.end()); nextToken = outcome.GetResult().GetNextToken(); } else { std::cerr << "Error: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!nextToken.empty() && count <= 50); // Limit to 50 events. std::cout << "Found " << allEvents.size() << " event(s)." << std::endl; for (auto &event: allEvents) { std::cout << "Event name: " << event.GetEventName() << std::endl; std::cout << "Event source: " << event.GetEventSource() << std::endl; std::cout << "Event id: " << event.GetEventId() << std::endl; std::cout << "Resources: " << std::endl; for (auto &resource: event.GetResources()) { std::cout << " " << resource.GetResourceName() << std::endl; } } return true; }
  • 如需 API 詳細資訊,請參閱 AWS SDK for C++ API 參考中的 LookupEvents

CLI
AWS CLI

查詢追蹤的事件

下列lookup-events命令會依 屬性 查詢 API 活動事件EventName

aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=ConsoleLogin

輸出:

{ "Events": [ { "EventId": "654ccbc0-ba0d-486a-9076-dbf7274677a7", "Username": "my-session-name", "EventTime": "2021-11-18T09:41:02-08:00", "CloudTrailEvent": "{\"eventVersion\":\"1.02\",\"userIdentity\":{\"type\":\"AssumedRole\",\"principalId\":\"AROAJIKPFTA72SWU4L7T4:my-session-name\",\"arn\":\"arn:aws:sts::123456789012:assumed-role/my-role/my-session-name\",\"accountId\":\"123456789012\",\"sessionContext\":{\"attributes\":{\"mfaAuthenticated\":\"false\",\"creationDate\":\"2016-01-26T21:42:12Z\"},\"sessionIssuer\":{\"type\":\"Role\",\"principalId\":\"AROAJIKPFTA72SWU4L7T4\",\"arn\":\"arn:aws:iam::123456789012:role/my-role\",\"accountId\":\"123456789012\",\"userName\":\"my-role\"}}},\"eventTime\":\"2016-01-26T21:42:12Z\",\"eventSource\":\"signin.amazonaws.com\",\"eventName\":\"ConsoleLogin\",\"awsRegion\":\"us-east-1\",\"sourceIPAddress\":\"72.21.198.70\",\"userAgent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36\",\"requestParameters\":null,\"responseElements\":{\"ConsoleLogin\":\"Success\"},\"additionalEventData\":{\"MobileVersion\":\"No\",\"MFAUsed\":\"No\"},\"eventID\":\"654ccbc0-ba0d-486a-9076-dbf7274677a7\",\"eventType\":\"AwsConsoleSignIn\",\"recipientAccountId\":\"123456789012\"}", "EventName": "ConsoleLogin", "Resources": [] } ] }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 LookupEvents

PowerShell
Tools for PowerShell

範例 1:傳回過去七天內發生的所有事件。根據預設,Cmdlet 會自動進行多次呼叫以交付所有事件,當服務指出沒有其他資料可用時結束。

Find-CTEvent

範例 2:傳回過去七天內發生的所有事件,指定不是目前 shell 預設的區域。

Find-CTEvent -Region eu-central-1

範例 3:傳回與 RunInstances API 呼叫相關聯的所有事件。

Find-CTEvent -LookupAttribute @{ AttributeKey="EventName"; AttributeValue="RunInstances" }

範例 4:傳回前 5 個可用的事件。

Find-CTEvent -MaxResult 5
  • 如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 LookupEvents

Ruby
SDK for Ruby
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

require 'aws-sdk-cloudtrail' # v2: require 'aws-sdk' # @param [Object] client def lookup_events_example(client) resp = client.lookup_events puts "Found #{resp.events.count} events:" resp.events.each do |e| puts "Event name: #{e.event_name}" puts "Event ID: #{e.event_id}" puts "Event time: #{e.event_time}" puts 'Resources:' e.resources.each do |r| puts " Name: #{r.resource_name}" puts " Type: #{r.resource_type}" puts '' end end end
  • 如需 API 詳細資訊,請參閱 AWS SDK for Ruby API 參考中的 LookupEvents

SDK for C++
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

// Routine which looks up events captured by AWS CloudTrail. /*! \param clientConfig: Aws client configuration. \return bool: Function succeeded. */ bool AwsDoc::CloudTrail::lookupEvents( const Aws::Client::ClientConfiguration &clientConfig) { Aws::CloudTrail::CloudTrailClient cloudtrail(clientConfig); Aws::String nextToken; // Used for pagination. Aws::Vector<Aws::CloudTrail::Model::Event> allEvents; Aws::CloudTrail::Model::LookupEventsRequest request; size_t count = 0; do { if (!nextToken.empty()) { request.SetNextToken(nextToken); } Aws::CloudTrail::Model::LookupEventsOutcome outcome = cloudtrail.LookupEvents( request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::CloudTrail::Model::Event> &events = outcome.GetResult().GetEvents(); count += events.size(); allEvents.insert(allEvents.end(), events.begin(), events.end()); nextToken = outcome.GetResult().GetNextToken(); } else { std::cerr << "Error: " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!nextToken.empty() && count <= 50); // Limit to 50 events. std::cout << "Found " << allEvents.size() << " event(s)." << std::endl; for (auto &event: allEvents) { std::cout << "Event name: " << event.GetEventName() << std::endl; std::cout << "Event source: " << event.GetEventSource() << std::endl; std::cout << "Event id: " << event.GetEventId() << std::endl; std::cout << "Resources: " << std::endl; for (auto &resource: event.GetResources()) { std::cout << " " << resource.GetResourceName() << std::endl; } } return true; }
  • 如需 API 詳細資訊,請參閱 AWS SDK for C++ API 參考中的 LookupEvents

下一個主題:

StartLogging

上一個主題:

ListTrails
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。