示例:通过 AWS CloudTrail 跟踪 Amazon EventBridge 中的 S3 批量操作作业 - Amazon Simple Storage Service
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

如果我们为英文版本指南提供翻译,那么如果存在任何冲突,将以英文版本指南为准。在提供翻译时使用机器翻译。

示例:通过 AWS CloudTrail 跟踪 Amazon EventBridge 中的 S3 批量操作作业

Amazon S3 批量操作作业活动在 AWS CloudTrail 中记录为事件。您可以在 Amazon EventBridge 中创建自定义规则,并将这些事件发送到所选的目标通知资源(例如 Amazon Simple Notification Service (Amazon SNS))。

注意

Amazon EventBridge 是管理事件的首选方式。Amazon CloudWatch Events 和 EventBridge 是相同的底层服务和 API,但 EventBridge 提供更多功能。您在 CloudWatch 或 EventBridge 中所做的更改将显示在每个控制台中。有关更多信息,请参阅 Amazon EventBridge 用户指南

发出到 CloudTrail 的 S3 批量操作事件

创建批量操作作业时,该作业将作为 JobCreated 事件记录到 CloudTrail 中。在作业运行时,它会在处理过程中更改状态,并且其他 JobStatusChanged 事件将记录到 CloudTrail 中。您可以在 CloudTrail 控制台中查看这些事件。有关 CloudTrail 的更多信息,请参阅 AWS CloudTrail User Guide

注意

仅 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": [] } }

使用 EventBridge 规则跟踪 S3 批量操作作业事件

以下示例说明如何在 Amazon EventBridge 中创建规则,以将 AWS CloudTrail 记录的 S3 批量操作事件捕获到所选目标。

为此,您可以执行使用 CloudTrail 创建针对 AWS API 调用触发的 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": [] } } }