本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用進階事件選取器篩選資料事件
本節說明如何使用進階事件選取器來建立精細的選取器,只記錄感興趣的特定資料事件,藉此協助您控制成本。
例如:
-
您可以透過在
eventName
欄位上新增篩選器來包含或排除特定API呼叫。 -
您可以在
resources.ARN
欄位上新增篩選器,以包含或排除特定資源的記錄。例如,如果您要記錄 S3 資料事件,您可以針對追蹤排除 S3 儲存貯體的記錄。 -
您可以在欄位上新增篩選器,選擇僅記錄唯寫事件或唯讀事件。
readOnly
下表提供有關進階事件選取器之可設定欄位的其他資訊。
欄位 | 必要 | 有效運算子 | 描述 |
---|---|---|---|
|
是 |
|
此欄位設定 |
|
是 |
|
此欄位用於選取您要記錄其資料事件的資源類型。「資料事件」表格會顯示可能的值。 |
|
否 |
|
這是選擇性欄位,用於根據 |
|
否 |
|
這是一個選擇性的欄位,用來搜尋或搜尋任何記錄到的資料事件 CloudTrail,例如或。 如果您正在使用 AWS CLI,您可以使用逗號分隔每個值來指定多個值。 如果您使用主控台,您可以為每 |
|
否 |
|
這是選擇性欄位,用來排除或包含特定資源的資料事件,方法是提供 如果您正在使用 AWS CLI,您可以使用逗號分隔每個值來指定多個值。 如果您使用主控台,您可以為每 |
若要使用 CloudTrail 主控台記錄資料事件,請選擇 [資料事件] 選項,然後在建立或更新追蹤或事件資料存放區時選取感興趣的資料事件類型。「資料事件」表格會顯示您可以在 CloudTrail 主控台上選擇的可能資料事件類型。
若要記錄資料事件 AWS CLI中,將--advanced-event-selector
參數設定為eventCategory
等於,Data
且resources.type
值等於您要記錄資料事件的資源類型值。「資料事件」表格會列出可用的資源類型。
例如,如果您想要記錄所有 Cognito Identity 集區的資料事件,請將--advanced-event-selectors
參數設定為如下所示:
--advanced-event-selectors '[ { "Name": "Log Cognito data events on Identity pools", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::Cognito::IdentityPool"] } ] } ]'
上述範例會記錄身分集區上的所有 Cognito 資料事件。您可以進一步調整進階事件選取器,以篩選eventName
readOnly
、和resources.ARN
欄位,以記錄感興趣的特定事件或排除不感興趣的事件。
您可以設定進階事件選取器,以根據多個欄位篩選資料事件。例如,您可以設定進階事件選取器來記錄所有 Amazon S3 PutObject
和DeleteObject
API呼叫,但排除特定 S3 儲存貯體的事件記錄,如下列範例所示。Replace (取代) amzn-s3-demo-bucket
用你的桶的名稱。
--advanced-event-selectors '[ { "Name": "Log PutObject and DeleteObject events for all but one bucket", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::S3::Object"] }, { "Field": "eventName", "Equals": ["PutObject","DeleteObject"] }, { "Field": "resources.ARN", "NotStartsWith": ["arn:aws:s3:::
amzn-s3-demo-bucket
/"] } ] } ]'
您也可以為欄位包含多個條件。如需如何評估多個條件的資訊,請參閱如何 CloudTrail 評估欄位的多個條件。
您可以使用進階事件選取器來記錄管理事件和資料事件。若要記錄多種資源類型的資料事件,請為您要記錄資料事件的每個資源類型新增欄位選取器陳述式。
注意
追蹤可以使用基本事件選取器或進階事件選取器,但不能同時使用兩者。如果您將進階事件選取器套用至追蹤,則會覆寫任何現有的基本事件選取器。
如何 CloudTrail 評估欄位的多個條件
對於進階事件選取器, CloudTrail 評估欄位的多個條件,如下所示:
-
DESELECT運營商AND會在一起。如果符合任何DESELECT操作員條件,則不會傳遞事件。以下是進階事件選取器的有效DESELECT運算子:
-
NotEndsWith
-
NotEquals
-
NotStartsWith
-
-
SELECT運營商是 OR 在一起。以下是進階事件選取器的有效SELECT運算子:
-
EndsWith
-
Equals
-
StartsWith
-
-
SELECT和DESELECT運營商的組合遵循上述規則,兩個組都AND會在一起。
顯示欄位多個條件的resources.ARN
範例
下列範例 event select 陳述式會收集資AWS::S3::Object
源類型的資料事件,並在resources.ARN
欄位上套用多個條件。
{ "Name": "S3Select", "FieldSelectors": [ { "Field": "eventCategory", "Equals": [ "Data" ] }, { "Field": "resources.type", "Equals": [ "AWS::S3::Object" ] }, { "Field": "resources.ARN", "Equals": [ "arn:aws:s3:::amzn-s3-demo-bucket/object1" ], "StartsWith": [ "arn:aws:s3:::amzn-s3-demo-bucket/" ], "EndsWith": [ "object3" ], "NotStartsWith": [ "arn:aws:s3:::amzn-s3-demo-bucket/deselect" ], "NotEndsWith": [ "object5" ], "NotEquals": [ "arn:aws:s3:::amzn-s3-demo-bucket/object6" ] } ] }
在上述範例中,在下列情況下,將交付資AWS::S3::Object
源的 Amazon S3 資料事件:
-
不符合下列DESELECT運算子條件:
-
該
resources.ARN
字段NotStartsWith
的值arn:aws:s3:::amzn-s3-demo-bucket/deselect
-
該
resources.ARN
字段NotEndsWith
的值object5
-
該
resources.ARN
字段NotEquals
的值arn:aws:s3:::amzn-s3-demo-bucket/object6
-
-
至少符合下列其中一個SELECT運算子條件:
-
該
resources.ARN
字段Equals
的值arn:aws:s3:::amzn-s3-demo-bucket/object1
-
該
resources.ARN
字段StartsWith
的值arn:aws:s3:::amzn-s3-demo-bucket/
-
該
resources.ARN
字段EndsWith
的值object3
-
根據評估邏輯:
-
的資料事件
amzn-s3-demo-bucket/object1
將會傳遞,因為它符合運Equals
算子的值,且不符合NotStartsWith
NotEndsWith
、和NotEquals
運算子的任何值。 -
的資料事件
amzn-s3-demo-bucket/object2
將會傳遞,因為它符合運StartsWith
算子的值,且不符合NotStartsWith
NotEndsWith
、和NotEquals
運算子的任何值。 -
的資料事件
amzn-s3-demo-bucket1/object3
會傳遞,因為它符合運EndsWith
算子,且與NotStartsWith
、NotEndsWith
運算子的任何值都不相NotEquals
符。 -
的資料事件
arn:aws:s3:::amzn-s3-demo-bucket/deselectObject4
將不會傳送,因為NotStartsWith
即使它符合StartsWith
運算子的條件,也符合的條件。 -
的資料事件
arn:aws:s3:::amzn-s3-demo-bucket/object5
將不會傳送,因為NotEndsWith
即使它符合StartsWith
運算子的條件,也符合的條件。 -
不
arn:aws:s3:::amzn-s3-demo-bucket/object6
會傳送的資料事件,因為它符合NotEquals
運算子的條件,即使它符合StartsWith
運算子的條件。
篩選資料事件的依據 eventName
使用進階事件選取器,您可以根據eventName
欄位的值包含或排除事件。過濾eventName
可以幫助控制成本,因為您可以避免產生成本 AWS 服務
您正在記錄數據事件以添加對新數據的支持APIs。
您可以在eventName
欄位中使用任何運算子。您可以使用它來搜尋或搜尋記錄到的任何資料事件 CloudTrail,例如或。PutBucket
GetSnapshotBlock
eventName
使用篩選資料事件 AWS Management Console
採取以下步驟使用 CloudTrail 控制台在eventName
字段上進行過濾。
-
當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:
-
選擇 [資料事件]。
-
選擇您要記錄其資料事件的資料事件類型。
-
在記錄選取器範本中,選擇自訂。
-
(選用) 在選取器名稱中,輸入用於識別選取器的名稱。選取器名稱是進階事件選擇器的描述性名稱,例如「僅為兩個 S3 儲存貯體記錄資料事件」。選取器名稱會列
Name
在進階事件選取器中,如果您展開檢視,則可檢JSON視。 -
在進階事件選取器中,執行下列動作以篩選
eventName
:-
對於「欄位」,請選擇eventName。
-
在「運算子」中,選擇條件運算子。在這個例子中,我們將選擇 equals,因為我們想要記錄一個特定的API呼叫。
-
在值中,輸入您要篩選的事件名稱。
-
若要篩選另一個
eventName
,請選擇 [+ 條件]。如需有關如何 CloudTrail 評估多個條件的資訊,請參閱如何 CloudTrail 評估欄位的多個條件。
-
-
選擇 [+ 欄位] 可在其他欄位上新增篩選條件。
-
eventName
使用篩選資料事件 AWS CLI
使用 AWS CLI,您可以篩選eventName
欄位以包含或排除特定事件。
如果您要更新現有的追蹤或事件資料存放區以記錄其他事件選取器,請執行追蹤的命令或事件資料存放區的get-event-selectors
命令來取得目前的get-event-data-store
事件選取器。然後,更新您的事件選取器,為您要記錄的每個資料資源類型新增欄位選取器。
下列範例會在追蹤上記錄 S3 資料事件。設定--advanced-event-selectors
為僅記錄GetObject
、PutObject
和DeleteObject
API呼叫的資料事件。
aws cloudtrail put-event-selectors \ --trail-name
trailName
\ --advanced-event-selectors '[ { "Name": "Log GetObject, PutObject and DeleteObject S3 data events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::S3::Object"] }, { "Field": "eventName", "Equals": ["GetObject","PutObject","DeleteObject"] } ] } ]'
下一個範例會建立新的事件資料存放區,用來記錄 EBS Direct 的資料事件,APIs但排除ListChangedBlocks
API呼叫。您可以使用 update-event-data-store用於更新既有事件資料倉庫的指令。
aws cloudtrail create-event-data-store \ --name "
eventDataStoreName
" --advanced-event-selectors '[ { "Name": "Log all EBS Direct API data events except ListChangedBlocks", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::EC2::Snapshot"] }, { "Field": "eventName", "NotEquals": ["ListChangedBlocks"] } ] } ]'
篩選資料事件的依據 resources.ARN
使用進階事件選取器,您可以篩選resources.ARN
欄位的值。
您可以將任何運算子搭配使用 resources.ARN
NotEquals
,但如果您使用Equals
或,則值必須完全符合您所指定resources.type
值的有效資源。ARN若要記錄特定 S3 儲存貯體中所有物件的所有資料事件,請使用StartsWith
運算子,並僅包含儲存貯體ARN作為相符值。
下表顯示每種格式的有效ARN格式resources.type
。
注意
您無法使用resources.ARN
欄位來篩選沒有的資源類型ARNs。
resources.type | 資源。 ARN |
---|---|
AWS::DynamoDB::Table1 |
|
AWS::Lambda::Function |
|
|
|
AWS::AppConfig::Configuration |
|
AWS::B2BI::Transformer |
|
AWS::Bedrock::AgentAlias |
|
AWS::Bedrock::FlowAlias |
|
AWS::Bedrock::Guardrail |
|
AWS::Bedrock::KnowledgeBase |
|
AWS::Cassandra::Table |
|
AWS::CloudFront::KeyValueStore |
|
AWS::CloudTrail::Channel |
|
AWS::CodeWhisperer::Customization |
|
AWS::CodeWhisperer::Profile |
|
AWS::Cognito::IdentityPool |
|
AWS::DynamoDB::Stream |
|
AWS::EC2::Snapshot |
|
AWS::EMRWAL::Workspace |
|
AWS::FinSpace::Environment |
|
AWS::Glue::Table |
|
AWS::GreengrassV2::ComponentVersion |
|
AWS::GreengrassV2::Deployment |
|
AWS::GuardDuty::Detector |
|
AWS::IoT::Certificate |
|
AWS::IoT::Thing |
|
AWS::IoTSiteWise::Asset |
|
AWS::IoTSiteWise::TimeSeries |
|
AWS::IoTTwinMaker::Entity |
|
AWS::IoTTwinMaker::Workspace |
|
AWS::KendraRanking::ExecutionPlan |
|
AWS::Kinesis::Stream |
|
AWS::Kinesis::StreamConsumer |
|
AWS::KinesisVideo::Stream |
|
AWS::MachineLearning::MlModel |
|
AWS::ManagedBlockchain::Network |
|
AWS::ManagedBlockchain::Node |
|
AWS::MedicalImaging::Datastore |
|
AWS::NeptuneGraph::Graph |
|
AWS::One::UKey |
|
AWS::One::User |
|
AWS::PaymentCryptography::Alias |
|
AWS::PaymentCryptography::Key |
|
AWS::PCAConnectorAD::Connector |
|
AWS::PCAConnectorSCEP::Connector |
|
AWS::QApps:QApp |
|
AWS::QBusiness::Application |
|
AWS::QBusiness::DataSource |
|
AWS::QBusiness::Index |
|
AWS::QBusiness::WebExperience |
|
AWS::RDS::DBCluster |
|
AWS::RUM::AppMonitor |
|
|
|
|
|
AWS::S3ObjectLambda::AccessPoint |
|
AWS::S3Outposts::Object |
|
AWS::SageMaker::Endpoint |
|
AWS::SageMaker::ExperimentTrialComponent |
|
AWS::SageMaker::FeatureGroup |
|
AWS::SCN::Instance |
|
AWS::ServiceDiscovery::Namespace |
|
AWS::ServiceDiscovery::Service |
|
AWS::SNS::PlatformEndpoint |
|
AWS::SNS::Topic |
|
AWS::SQS::Queue |
|
AWS::SSM::ManagedNode |
ARN必須採用下列其中一種格式:
|
AWS::SSMMessages::ControlChannel |
|
AWS::StepFunctions::StateMachine |
ARN必須採用下列其中一種格式:
|
AWS::SWF::Domain |
|
AWS::ThinClient::Device |
|
AWS::ThinClient::Environment |
|
AWS::Timestream::Database |
|
AWS::Timestream::Table |
|
AWS::VerifiedPermissions::PolicyStore |
|
1 對於已啟用串流的資料表,資料事件中的 resources
欄位會同時包含 AWS::DynamoDB::Stream
和 AWS::DynamoDB::Table
。如果您指定 AWS::DynamoDB::Table
作為 resources.type
,則會根據預設同時記錄 DynamoDB 資料表和 DynamoDB 串流事件。若要排除串流事件,請在eventName
欄位上新增篩選器。
2 若要記錄特定 S3 儲存貯體中所有物件的所有資料事件,請使用StartsWith
運算子,並僅包含儲存貯體ARN作為相符值。末尾斜線是有意保留,請勿排除。
3 若要記錄 S3 存取點中所有物件的事件,建議您僅使用存取點ARN,不要包含物件路徑,並使用StartsWith
或NotStartsWith
運算子。
resources.ARN
使用篩選資料事件 AWS Management Console
採取以下步驟使用 CloudTrail 控制台在resources.ARN
字段上進行過濾。
-
當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:
-
選擇 [資料事件]。
-
選擇您要記錄其資料事件的資料事件類型。
-
在記錄選取器範本中,選擇自訂。
-
(選用) 在選取器名稱中,輸入用於識別選取器的名稱。選取器名稱是進階事件選擇器的描述性名稱,例如「僅為兩個 S3 儲存貯體記錄資料事件」。選取器名稱會列
Name
在進階事件選取器中,如果您展開檢視,則可檢JSON視。 -
在進階事件選取器中,執行下列動作以篩選
resources.ARN
:-
對於「欄位」,請選擇資源。 ARN。
-
在「運算子」中,選擇條件運算子。在此範例中,我們將選擇「開始為」,因為我們想要記錄特定 S3 儲存貯體的資料事件。
-
在值中,輸入您ARN的資源類型 (例如,
arn:aws:s3:::amzn-s3-demo-bucket
). -
若要篩選另一個
resources.ARN
,請選擇 [+ 條件]。如需有關如何 CloudTrail 評估多個條件的資訊,請參閱如何 CloudTrail 評估欄位的多個條件。
-
-
選擇 [+ 欄位] 可在其他欄位上新增篩選條件。
-
resources.ARN
使用篩選資料事件 AWS CLI
使用 AWS CLI,您可以篩選resources.ARN
欄位以記錄特定事件,ARN或排除特定記錄的記錄ARN。
如果您要更新現有的追蹤或事件資料存放區以記錄其他事件選取器,請執行追蹤的命令或事件資料存放區的get-event-selectors
命令來取得目前的get-event-data-store
事件選取器。然後,更新您的事件選取器,為您要記錄的每個資料資源類型新增欄位選取器。
以下範例說明如何設定您的追蹤在特定 S3 儲存貯體中包含所有 Amazon S3 物件的所有管理和資料事件。resources.type
欄位的 S3 事件的值是 AWS::S3::Object
。由於 S3 物件和 S3 儲存貯體的ARN值略有不同,因此您必須新增的StartsWith
運算子resources.ARN
才能擷取所有事件。
aws cloudtrail put-event-selectors \ --trail-name
TrailName
\ --regionregion
\ --advanced-event-selectors \ '[ { "Name": "S3EventSelector", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::S3::Object"] }, { "Field": "resources.ARN", "StartsWith": ["arn:aws:s3:::amzn-s3-demo-bucket
/"] } ] } ]'
依readOnly
值篩選資料事件
使用進階事件選取器,您可以根據readOnly
欄位的值進行篩選。
您只能在readOnly
欄位中使用Equals
運算子。您可以將readOnly
值設定為true
或false
。如果您未新增此欄位,則會同時 CloudTrail 記錄讀取和寫入事件。true
記錄檔的值僅讀取事件。false
記錄檔的值僅寫入事件。
使用readOnly
值篩選資料事件 AWS Management Console
採取以下步驟使用 CloudTrail 控制台在readOnly
字段上進行過濾。
-
當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:
-
選擇 [資料事件]。
-
選擇您要記錄其資料事件的資料事件類型。
-
針對記錄選取器範本,選擇適合您使用案例的範本。
如果你打算這樣做 選擇此記錄檔選取器範本 僅記錄讀取事件,不套用其他篩選器 (例如,在
resources.ARN
值上)。記錄 readOnly 事件
僅記錄寫入事件,不套用其他篩選器 (例如,在
resources.ARN
值上)。記錄 writeOnly 事件
篩選
readOnly
值並套用其他篩選器 (例如,在resources.ARN
值上)。Custom (自訂)
在進階事件選取器中,執行下列動作以篩選
readOnly
值:若要記錄寫入事件
-
對於「欄位」,請選擇readOnly。
-
對於運算子,選擇 equals。
-
針對數值,輸入
false
。 -
選擇 [+ 欄位] 可在其他欄位上新增篩選條件。
若要記錄讀取事件
-
對於「欄位」,請選擇readOnly。
-
對於運算子,選擇 equals。
-
針對數值,輸入
true
。 -
選擇 [+ 欄位] 可在其他欄位上新增篩選條件。
-
-
使用readOnly
值篩選資料事件 AWS CLI
使用 AWS CLI,您可以在readOnly
欄位上進行篩選。
您只能在readOnly
欄位中使用Equals
運算子。您可以將readOnly
值設定為true
或false
。如果您未新增此欄位,則會同時 CloudTrail記錄讀取和寫入事件。true
記錄檔的值僅讀取事件。false
記錄檔的值僅寫入事件。
如果您要更新現有的追蹤或事件資料存放區以記錄其他事件選取器,請執行追蹤的命令或事件資料存放區的get-event-selectors
命令來取得目前的get-event-data-store
事件選取器。然後,更新您的事件選取器,為您要記錄的每個資料資源類型新增欄位選取器。
下列範例顯示如何設定追蹤,以記錄所有 Amazon S3 物件的唯讀資料事件。
aws cloudtrail put-event-selectors \ --trail-name
TrailName
\ --regionregion
\ --advanced-event-selectors '[ { "Name": "Log read-only S3 data events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::S3::Object"] }, { "Field": "readOnly", "Equals": ["true"] } ] } ]'
下一個範例會建立新的事件資料存放區,該資料存放區僅記錄 Direct 的唯寫資料事件。EBS APIs您可以使用 update-event-data-store用於更新既有事件資料倉庫的指令。
aws cloudtrail create-event-data-store \ --name "
eventDataStoreName
" \ --advanced-event-selectors \ '[ { "Name": "Log write-only EBS Direct API data events", "FieldSelectors": [ { "Field": "eventCategory", "Equals": ["Data"] }, { "Field": "resources.type", "Equals": ["AWS::EC2::Snapshot"] }, { "Field": "readOnly", "Equals": ["false"] } ] } ]'