使用進階事件選取器篩選資料事件 - AWS CloudTrail

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

使用進階事件選取器篩選資料事件

本節說明如何使用進階事件選取器來建立精細的選取器,只記錄感興趣的特定資料事件,藉此協助您控制成本。

例如:

  • 您可以透過在eventName欄位上新增篩選器來包含或排除特定API呼叫。

  • 您可以在resources.ARN欄位上新增篩選器,以包含或排除特定資源的記錄。例如,如果您要記錄 S3 資料事件,您可以針對追蹤排除 S3 儲存貯體的記錄。

  • 您可以在欄位上新增篩選器,選擇僅記錄唯寫事件或唯讀事件。readOnly

下表提供有關進階事件選取器之可設定欄位的其他資訊。

欄位 必要 有效運算子 描述

eventCategory

Equals

此欄位設定Data為記錄資料事件。

resources.type

Equals

此欄位用於選取您要記錄其資料事件的資源類型。「資料事件」表格會顯示可能的值。

readOnly

Equals

這是選擇性欄位,用於根據readOnly值包含或排除資料事件。true記錄檔的值僅讀取事件。false記錄檔的值僅寫入事件。如果您未新增此欄位,則會同時 CloudTrail 記錄讀取和寫入事件。

eventName

EndsWith

Equals

NotEndsWith

NotEquals

NotStartsWith

StartsWith

這是一個選擇性的欄位,用來搜尋或搜尋任何記錄到的資料事件 CloudTrail,例如或。PutBucket GetSnapshotBlock

如果您正在使用 AWS CLI,您可以使用逗號分隔每個值來指定多個值。

如果您使用主控台,您可以為每eventName個要篩選的項目建立條件來指定多個值。

resources.ARN

EndsWith

Equals

NotEndsWith

NotEquals

NotStartsWith

StartsWith

這是選擇性欄位,用來排除或包含特定資源的資料事件,方法是提供resources.ARN. 您可以使用任何運算子resources.ARN,但如果您使用EqualsNotEquals,值必須完全符合resoureces.type您指定的有效資源。ARN若要記錄特定 S3 儲存貯體中所有物件的所有資料事件,請使用StartsWith運算子,並僅包含儲存貯體ARN作為相符值。

如果您正在使用 AWS CLI,您可以使用逗號分隔每個值來指定多個值。

如果您使用主控台,您可以為每resources.ARN個要篩選的項目建立條件來指定多個值。

若要使用 CloudTrail 主控台記錄資料事件,請選擇 [資料事件] 選項,然後在建立或更新追蹤或事件資料存放區時選取感興趣的資料事件類型。「資料事件」表格會顯示您可以在 CloudTrail 主控台上選擇的可能資料事件類型。

在主控台上選取SNS主題資料事件類型。

若要記錄資料事件 AWS CLI中,將--advanced-event-selector參數設定為eventCategory等於,Dataresources.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 資料事件。您可以進一步調整進階事件選取器,以篩選eventNamereadOnly、和resources.ARN欄位,以記錄感興趣的特定事件或排除不感興趣的事件。

您可以設定進階事件選取器,以根據多個欄位篩選資料事件。例如,您可以設定進階事件選取器來記錄所有 Amazon S3 PutObjectDeleteObjectAPI呼叫,但排除特定 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 資料事件:

  1. 不符合下列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

  2. 至少符合下列其中一個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

根據評估邏輯:

  1. 的資料事件amzn-s3-demo-bucket/object1將會傳遞,因為它符合運Equals算子的值,且不符合NotStartsWithNotEndsWith、和NotEquals運算子的任何值。

  2. 的資料事件amzn-s3-demo-bucket/object2將會傳遞,因為它符合運StartsWith算子的值,且不符合NotStartsWithNotEndsWith、和NotEquals運算子的任何值。

  3. 的資料事件amzn-s3-demo-bucket1/object3會傳遞,因為它符合運EndsWith算子,且與NotStartsWithNotEndsWith運算子的任何值都不相NotEquals符。

  4. 的資料事件arn:aws:s3:::amzn-s3-demo-bucket/deselectObject4將不會傳送,因為NotStartsWith即使它符合StartsWith運算子的條件,也符合的條件。

  5. 的資料事件arn:aws:s3:::amzn-s3-demo-bucket/object5將不會傳送,因為NotEndsWith即使它符合StartsWith運算子的條件,也符合的條件。

  6. 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字段上進行過濾。

  1. 請遵循建立追蹤程序中的步驟,或遵循建立事件資料存放區程序中的步驟。

  2. 當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:

    1. 選擇 [資料事件]。

    2. 選擇您要記錄其資料事件的資料事件類型

    3. 在記錄選取器範本中,選擇自訂

    4. (選用) 在選取器名稱中,輸入用於識別選取器的名稱。選取器名稱是進階事件選擇器的描述性名稱,例如「僅為兩個 S3 儲存貯體記錄資料事件」。選取器名稱會列Name在進階事件選取器中,如果您展開檢視,則可檢JSON視

    5. 進階事件選取器中,執行下列動作以篩選eventName

      1. 對於「欄位」,請選擇eventName

      2. 在「運算子」中,選擇條件運算子。在這個例子中,我們將選擇 equals,因為我們想要記錄一個特定的API呼叫。

      3. 中,輸入您要篩選的事件名稱。

      4. 若要篩選另一個eventName,請選擇 [+ 條件]。如需有關如何 CloudTrail 評估多個條件的資訊,請參閱如何 CloudTrail 評估欄位的多個條件

      篩選 S3 資料事件的依據 eventName
    6. 選擇 [+ 欄位] 可在其他欄位上新增篩選條件。

eventName使用篩選資料事件 AWS CLI

使用 AWS CLI,您可以篩選eventName欄位以包含或排除特定事件。

如果您要更新現有的追蹤或事件資料存放區以記錄其他事件選取器,請執行追蹤的命令或事件資料存放區的get-event-selectors命令來取得目前的get-event-data-store事件選取器。然後,更新您的事件選取器,為您要記錄的每個資料資源類型新增欄位選取器。

下列範例會在追蹤上記錄 S3 資料事件。設定--advanced-event-selectors為僅記錄GetObjectPutObjectDeleteObjectAPI呼叫的資料事件。

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但排除ListChangedBlocksAPI呼叫。您可以使用 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.ARNNotEquals,但如果您使用Equals或,則值必須完全符合您所指定resources.type值的有效資源。ARN若要記錄特定 S3 儲存貯體中所有物件的所有資料事件,請使用StartsWith運算子,並僅包含儲存貯體ARN作為相符值。

下表顯示每種格式的有效ARN格式resources.type

注意

您無法使用resources.ARN欄位來篩選沒有的資源類型ARNs。

resources.type 資源。 ARN
AWS::DynamoDB::Table1
arn:partition:dynamodb:region:account_ID:table/table_name
AWS::Lambda::Function
arn:partition:lambda:region:account_ID:function:function_name

AWS::S3::Object2

arn:partition:s3:::amzn-s3-demo-bucket/ arn:partition:s3:::amzn-s3-demo-bucket/object_or_file_name/
AWS::AppConfig::Configuration
arn:partition:appconfig:region:account_ID:application/application_ID/environment/environment_ID/configuration/configuration_profile_ID
AWS::B2BI::Transformer
arn:partition:b2bi:region:account_ID:transformer/transformer_ID
AWS::Bedrock::AgentAlias
arn:partition:bedrock:region:account_ID:agent-alias/agent_ID/alias_ID
AWS::Bedrock::FlowAlias
arn:partition:bedrock:region:account_ID:flow/flow_ID/alias/alias_ID
AWS::Bedrock::Guardrail
arn:partition:bedrock:region:account_ID:guardrail/guardrail_ID
AWS::Bedrock::KnowledgeBase
arn:partition:bedrock:region:account_ID:knowledge-base/knowledge_base_ID
AWS::Cassandra::Table
arn:partition:cassandra:region:account_ID:keyspace/keyspace_name/table/table_name
AWS::CloudFront::KeyValueStore
arn:partition:cloudfront:region:account_ID:key-value-store/KVS_name
AWS::CloudTrail::Channel
arn:partition:cloudtrail:region:account_ID:channel/channel_UUID
AWS::CodeWhisperer::Customization
arn:partition:codewhisperer:region:account_ID:customization/customization_ID
AWS::CodeWhisperer::Profile
arn:partition:codewhisperer:region:account_ID:profile/profile_ID
AWS::Cognito::IdentityPool
arn:partition:cognito-identity:region:account_ID:identitypool/identity_pool_ID
AWS::DynamoDB::Stream
arn:partition:dynamodb:region:account_ID:table/table_name/stream/date_time
AWS::EC2::Snapshot
arn:partition:ec2:region::snapshot/snapshot_ID
AWS::EMRWAL::Workspace
arn:partition:emrwal:region:account_ID:workspace/workspace_name
AWS::FinSpace::Environment
arn:partition:finspace:region:account_ID:environment/environment_ID
AWS::Glue::Table
arn:partition:glue:region:account_ID:table/database_name/table_name
AWS::GreengrassV2::ComponentVersion
arn:partition:greengrass:region:account_ID:components/component_name
AWS::GreengrassV2::Deployment
arn:partition:greengrass:region:account_ID:deployments/deployment_ID
AWS::GuardDuty::Detector
arn:partition:guardduty:region:account_ID:detector/detector_ID
AWS::IoT::Certificate
arn:partition:iot:region:account_ID:cert/certificate_ID
AWS::IoT::Thing
arn:partition:iot:region:account_ID:thing/thing_ID
AWS::IoTSiteWise::Asset
arn:partition:iotsitewise:region:account_ID:asset/asset_ID
AWS::IoTSiteWise::TimeSeries
arn:partition:iotsitewise:region:account_ID:timeseries/timeseries_ID
AWS::IoTTwinMaker::Entity
arn:partition:iottwinmaker:region:account_ID:workspace/workspace_ID/entity/entity_ID
AWS::IoTTwinMaker::Workspace
arn:partition:iottwinmaker:region:account_ID:workspace/workspace_ID
AWS::KendraRanking::ExecutionPlan
arn:partition:kendra-ranking:region:account_ID:rescore-execution-plan/rescore_execution_plan_ID
AWS::Kinesis::Stream
arn:partition:kinesis:region:account_ID:stream/stream_name
AWS::Kinesis::StreamConsumer
arn:partition:kinesis:region:account_ID:stream_type/stream_name/consumer/consumer_name:consumer_creation_timestamp
AWS::KinesisVideo::Stream
arn:partition:kinesisvideo:region:account_ID:stream/stream_name/creation_time
AWS::MachineLearning::MlModel
arn:partition:machinelearning:region:account_ID:mlmodel/model_ID
AWS::ManagedBlockchain::Network
arn:partition:managedblockchain:::networks/network_name
AWS::ManagedBlockchain::Node
arn:partition:managedblockchain:region:account_ID:nodes/node_ID
AWS::MedicalImaging::Datastore
arn:partition:medical-imaging:region:account_ID:datastore/data_store_ID
AWS::NeptuneGraph::Graph
arn:partition:neptune-graph:region:account_ID:graph/graph_ID
AWS::One::UKey
arn:partition:one:region:account_ID:user/user_ID/u-key/u-key_ID
AWS::One::User
arn:partition:one:region:account_ID:user/user_ID
AWS::PaymentCryptography::Alias
arn:partition:payment-cryptography:region:account_ID:alias/alias
AWS::PaymentCryptography::Key
arn:partition:payment-cryptography:region:account_ID:key/key_ID
AWS::PCAConnectorAD::Connector
arn:partition:pca-connector-ad:region:account_ID:connector/connector_ID
AWS::PCAConnectorSCEP::Connector
arn:partition:pca-connector-scep:region:account_ID:connector/connector_ID
AWS::QApps:QApp
arn:partition:qapps:region:account_ID:application/application_UUID/qapp/qapp_UUID
AWS::QBusiness::Application
arn:partition:qbusiness:region:account_ID:application/application_ID
AWS::QBusiness::DataSource
arn:partition:qbusiness:region:account_ID:application/application_ID/index/index_ID/data-source/datasource_ID
AWS::QBusiness::Index
arn:partition:qbusiness:region:account_ID:application/application_ID/index/index_ID
AWS::QBusiness::WebExperience
arn:partition:qbusiness:region:account_ID:application/application_ID/web-experience/web_experienc_ID
AWS::RDS::DBCluster
arn:partition:rds:region:account_ID:cluster/cluster_name
AWS::RUM::AppMonitor
arn:partition:rum:region:account_ID:appmonitor/app_monitor_name

AWS::S3::AccessPoint3

arn:partition:s3:region:account_ID:accesspoint/access_point_name

AWS::S3Express::Object

arn:partition:s3express:region:account_ID:bucket/bucket_name
AWS::S3ObjectLambda::AccessPoint
arn:partition:s3-object-lambda:region:account_ID:accesspoint/access_point_name
AWS::S3Outposts::Object
arn:partition:s3-outposts:region:account_ID:object_path
AWS::SageMaker::Endpoint
arn:partition:sagemaker:region:account_ID:endpoint/endpoint_name
AWS::SageMaker::ExperimentTrialComponent
arn:partition:sagemaker:region:account_ID:experiment-trial-component/experiment_trial_component_name
AWS::SageMaker::FeatureGroup
arn:partition:sagemaker:region:account_ID:feature-group/feature_group_name
AWS::SCN::Instance
arn:partition:scn:region:account_ID:instance/instance_ID
AWS::ServiceDiscovery::Namespace
arn:partition:servicediscovery:region:account_ID:namespace/namespace_ID
AWS::ServiceDiscovery::Service
arn:partition:servicediscovery:region:account_ID:service/service_ID
AWS::SNS::PlatformEndpoint
arn:partition:sns:region:account_ID:endpoint/endpoint_type/endpoint_name/endpoint_ID
AWS::SNS::Topic
arn:partition:sns:region:account_ID:topic_name
AWS::SQS::Queue
arn:partition:sqs:region:account_ID:queue_name
AWS::SSM::ManagedNode

ARN必須採用下列其中一種格式:

  • arn:partition:ssm:region:account_ID:managed-instance/instance_ID

  • arn:partition:ec2:region:account_ID:instance/instance_ID

AWS::SSMMessages::ControlChannel
arn:partition:ssmmessages:region:account_ID:control-channel/control_channel_ID
AWS::StepFunctions::StateMachine

ARN必須採用下列其中一種格式:

  • arn:partition:states:region:account_ID:stateMachine:stateMachine_name

  • arn:partition:states:region:account_ID:stateMachine:stateMachine_name/label_name

AWS::SWF::Domain
arn:partition:swf:region:account_ID:/domain/domain_name
AWS::ThinClient::Device
arn:partition:thinclient:region:account_ID:device/device_ID
AWS::ThinClient::Environment
arn:partition:thinclient:region:account_ID:environment/environment_ID
AWS::Timestream::Database
arn:partition:timestream:region:account_ID:database/database_name
AWS::Timestream::Table
arn:partition:timestream:region:account_ID:database/database_name/table/table_name
AWS::VerifiedPermissions::PolicyStore
arn:partition:verifiedpermissions:region:account_ID:policy-store/policy_store_ID

1 對於已啟用串流的資料表,資料事件中的 resources 欄位會同時包含 AWS::DynamoDB::StreamAWS::DynamoDB::Table。如果您指定 AWS::DynamoDB::Table 作為 resources.type,則會根據預設同時記錄 DynamoDB 資料表和 DynamoDB 串流事件。若要排除串流事件,請在eventName欄位上新增篩選器。

2 若要記錄特定 S3 儲存貯體中所有物件的所有資料事件,請使用StartsWith運算子,並僅包含儲存貯體ARN作為相符值。末尾斜線是有意保留,請勿排除。

3 若要記錄 S3 存取點中所有物件的事件,建議您僅使用存取點ARN,不要包含物件路徑,並使用StartsWithNotStartsWith運算子。

resources.ARN使用篩選資料事件 AWS Management Console

採取以下步驟使用 CloudTrail 控制台在resources.ARN字段上進行過濾。

  1. 請遵循建立追蹤程序中的步驟,或遵循建立事件資料存放區程序中的步驟。

  2. 當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:

    1. 選擇 [資料事件]。

    2. 選擇您要記錄其資料事件的資料事件類型

    3. 在記錄選取器範本中,選擇自訂

    4. (選用) 在選取器名稱中,輸入用於識別選取器的名稱。選取器名稱是進階事件選擇器的描述性名稱,例如「僅為兩個 S3 儲存貯體記錄資料事件」。選取器名稱會列Name在進階事件選取器中,如果您展開檢視,則可檢JSON視

    5. 進階事件選取器中,執行下列動作以篩選resources.ARN

      1. 對於「欄位」,請選擇資源。 ARN

      2. 在「運算子」中,選擇條件運算子。在此範例中,我們將選擇「開始為」,因為我們想要記錄特定 S3 儲存貯體的資料事件。

      3. 中,輸入您ARN的資源類型 (例如,arn:aws:s3:::amzn-s3-demo-bucket).

      4. 若要篩選另一個resources.ARN,請選擇 [+ 條件]。如需有關如何 CloudTrail 評估多個條件的資訊,請參閱如何 CloudTrail 評估欄位的多個條件

      篩選 S3 資料事件的依據 resources.ARN
    6. 選擇 [+ 欄位] 可在其他欄位上新增篩選條件。

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 \ --region region \ --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值設定為truefalse。如果您未新增此欄位,則會同時 CloudTrail 記錄讀取和寫入事件。true記錄檔的值僅讀取事件。false記錄檔的值僅寫入事件。

使用readOnly值篩選資料事件 AWS Management Console

採取以下步驟使用 CloudTrail 控制台在readOnly字段上進行過濾。

  1. 請遵循建立追蹤程序中的步驟,或遵循建立事件資料存放區程序中的步驟。

  2. 當您按照步驟建立追蹤或事件資料倉庫時,請進行下列選擇:

    1. 選擇 [資料事件]。

    2. 選擇您要記錄其資料事件的資料事件類型

    3. 針對記錄選取器範本,選擇適合您使用案例的範本。

      選擇資料事件的記錄選取器範本
      如果你打算這樣做 選擇此記錄檔選取器範本

      僅記錄讀取事件,不套用其他篩選器 (例如,在resources.ARN值上)。

      記錄 readOnly 事件

      僅記錄寫入事件,不套用其他篩選器 (例如,在resources.ARN值上)。

      記錄 writeOnly 事件

      篩選readOnly值並套用其他篩選器 (例如,在resources.ARN值上)。

      Custom (自訂)

      進階事件選取器中,執行下列動作以篩選readOnly值:

      若要記錄寫入事件
      1. 對於「欄位」,請選擇readOnly

      2. 對於運算子,選擇 equals

      3. 針對數值,輸入 false

      4. 選擇 [+ 欄位] 可在其他欄位上新增篩選條件。

      若要記錄讀取事件
      1. 對於「欄位」,請選擇readOnly

      2. 對於運算子,選擇 equals

      3. 針對數值,輸入 true

      4. 選擇 [+ 欄位] 可在其他欄位上新增篩選條件。

使用readOnly值篩選資料事件 AWS CLI

使用 AWS CLI,您可以在readOnly欄位上進行篩選。

您只能在readOnly欄位中使用Equals運算子。您可以將readOnly值設定為truefalse。如果您未新增此欄位,則會同時 CloudTrail記錄讀取和寫入事件。true記錄檔的值僅讀取事件。false記錄檔的值僅寫入事件。

如果您要更新現有的追蹤或事件資料存放區以記錄其他事件選取器,請執行追蹤的命令或事件資料存放區的get-event-selectors命令來取得目前的get-event-data-store事件選取器。然後,更新您的事件選取器,為您要記錄的每個資料資源類型新增欄位選取器。

下列範例顯示如何設定追蹤,以記錄所有 Amazon S3 物件的唯讀資料事件。

aws cloudtrail put-event-selectors \ --trail-name TrailName \ --region region \ --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"] } ] } ]'