範例:透過 追蹤 Amazon EventBridge 中的 S3 批次操作任務 AWS CloudTrail - Amazon Simple Storage Service

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

範例:透過 追蹤 Amazon EventBridge 中的 S3 批次操作任務 AWS CloudTrail

Amazon S3 批次操作任務活動會記錄為 AWS CloudTrail中的事件。您可以在 Amazon EventBridge 中建立自訂規則,並將這些事件傳送至您選擇的目標通知資源,例如 Amazon Simple Notification Service (Amazon SNS)。

注意

Amazon EventBridge 是管理事件的首選方式。Amazon CloudWatch Events 和 EventBridge 是相同的基礎服務和 API,但 EventBridge 提供了更多功能。您在 CloudWatch 或 EventBridge 中進行的變更會顯示在每個主控台中。如需詳細資訊,請參閱 Amazon EventBridge 使用者指南

in CloudTrail 記錄的 S3 批次操作事件

建立批次操作任務時,它會在 CloudTrail 中記錄為JobCreated事件。當任務執行時,它會在處理期間變更狀態,而其他JobStatusChanged事件則會記錄在 CloudTrail 中。您可以在 CloudTrail 主控台上檢視這些事件。如需 CloudTrail 的詳細資訊,請參閱 AWS CloudTrail 使用者指南

注意

只有 S3 批次操作任務status-change事件會記錄在 CloudTrail 中。

範例 — 由 CloudTrail 記錄的 S3 批次操作任務完成事件
{ "eventVersion": "1.05", "userIdentity": { "accountId": "123456789012", "invokedBy": "s3.amazonaws.com" }, "eventTime": "2020-02-05T18:25:30Z", "eventSource": "s3.amazonaws.com", "eventName": "JobStatusChanged", "awsRegion": "us-west-2", "sourceIPAddress": "s3.amazonaws.com", "userAgent": "s3.amazonaws.com", "requestParameters": null, "responseElements": null, "eventID": "f907577b-bf3d-4c53-b9ed-8a83a118a554", "readOnly": false, "eventType": "AwsServiceEvent", "recipientAccountId": "123412341234", "serviceEventDetails": { "jobId": "d6e58ec4-897a-4b6d-975f-10d7f0fb63ce", "jobArn": "arn:aws:s3:us-west-2:181572960644:job/d6e58ec4-897a-4b6d-975f-10d7f0fb63ce", "status": "Complete", "jobEventId": "b268784cf0a66749f1a05bce259804f5", "failureCodes": [], "statusChangeReason": [] } }

用於追蹤 S3 批次操作任務事件的 EventBridge 規則

下列範例示範如何在 Amazon EventBridge 中建立規則,以將 記錄的 S3 批次操作事件擷取 AWS CloudTrail 至您選擇的目標。

若要這麼做,您可以遵循 Create EventBridge 規則中對事件做出反應的所有步驟來建立規則。您可以在情況適用時貼上下列 S3 批次操作自訂事件模式政策,然後選擇您所選的目標服務。

S3 批次操作自訂事件模式政策

{ "source": [ "aws.s3" ], "detail-type": [ "AWS Service Event via CloudTrail" ], "detail": { "eventSource": [ "s3.amazonaws.com" ], "eventName": [ "JobCreated", "JobStatusChanged" ] } }

下列範例是兩個批次操作事件,這些事件是從 EventBridge 事件規則傳送至 Amazon Simple Queue Service (Amazon SQS)。批次操作任務處理時,會經歷許多不同的狀態 (NewPreparingActive 等),因此您可以預期每個任務都會收到幾則訊息。

範例 — JobCreated 範例事件
{ "version": "0", "id": "51dc8145-541c-5518-2349-56d7dffdf2d8", "detail-type": "AWS Service Event via CloudTrail", "source": "aws.s3", "account": "123456789012", "time": "2020-02-27T15:25:49Z", "region": "us-east-1", "resources": [], "detail": { "eventVersion": "1.05", "userIdentity": { "accountId": "11112223334444", "invokedBy": "s3.amazonaws.com" }, "eventTime": "2020-02-27T15:25:49Z", "eventSource": "s3.amazonaws.com", "eventName": "JobCreated", "awsRegion": "us-east-1", "sourceIPAddress": "s3.amazonaws.com", "userAgent": "s3.amazonaws.com", "eventID": "7c38220f-f80b-4239-8b78-2ed867b7d3fa", "readOnly": false, "eventType": "AwsServiceEvent", "serviceEventDetails": { "jobId": "e849b567-5232-44be-9a0c-40988f14e80c", "jobArn": "arn:aws:s3:us-east-1:181572960644:job/e849b567-5232-44be-9a0c-40988f14e80c", "status": "New", "jobEventId": "f177ff24f1f097b69768e327038f30ac", "failureCodes": [], "statusChangeReason": [] } } }
範例 — JobStatusChanged 任務完成事件
{ "version": "0", "id": "c8791abf-2af8-c754-0435-fd869ce25233", "detail-type": "AWS Service Event via CloudTrail", "source": "aws.s3", "account": "123456789012", "time": "2020-02-27T15:26:42Z", "region": "us-east-1", "resources": [], "detail": { "eventVersion": "1.05", "userIdentity": { "accountId": "1111222233334444", "invokedBy": "s3.amazonaws.com" }, "eventTime": "2020-02-27T15:26:42Z", "eventSource": "s3.amazonaws.com", "eventName": "JobStatusChanged", "awsRegion": "us-east-1", "sourceIPAddress": "s3.amazonaws.com", "userAgent": "s3.amazonaws.com", "eventID": "0238c1f7-c2b0-440b-8dbd-1ed5e5833afb", "readOnly": false, "eventType": "AwsServiceEvent", "serviceEventDetails": { "jobId": "e849b567-5232-44be-9a0c-40988f14e80c", "jobArn": "arn:aws:s3:us-east-1:181572960644:job/e849b567-5232-44be-9a0c-40988f14e80c", "status": "Complete", "jobEventId": "51f5ac17dba408301d56cd1b2c8d1e9e", "failureCodes": [], "statusChangeReason": [] } } }