Amazon Simple Storage Service
开发人员指南 (API Version 2006-03-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

事件消息结构

Amazon S3 发送以发布事件的通知消息是具有以下结构的 JSON 消息。请注意以下几点:

  • 如果您希望通过联系 Amazon S3 支持来跟踪请求,则 responseElements 键值很有用。x-amz-request-idx-amz-id-2 都可帮助 Amazon S3 跟踪单个请求。这些值与 Amazon S3 为响应您的原始 PUT 请求 (该请求启动了事件) 而返回的值相同。

  • s3 键提供事件中涉及的存储桶和对象的相关信息。请注意,对象键名称值进行了 URL 编码。例如“red flower.jpg”变为“red+flower.jpg”。

  • sequencer 键提供了确定事件顺序的方法。无法保证事件通知按事件发生的顺序到达。但是,来自创建对象 (PUT) 和删除对象的事件的通知包含 sequencer,可用于确定给定对象键的事件的顺序。

    如果将来自同一对象键上的两个事件通知的 sequencer 字符串进行比较,就会发现 sequencer 十六进制值较大的事件通知是后发生的事件。如果您正在使用事件通知来维护 Amazon S3 对象的单独数据库或索引,则您可能需要在处理每个事件通知时比较和存储 sequencer 值。

    请注意:

    • sequencer 不能用于确定不同对象键上的事件的顺序。

    • 排序器可以有不同的长度。因此,为了比较这些值,您首先要用零填补较短的值的右侧,然后进行字母表顺序比较。

Copy
{ "Records":[ { "eventVersion":"2.0", "eventSource":"aws:s3", "awsRegion":"us-east-1", "eventTime":The time, in ISO-8601 format, for example, 1970-01-01T00:00:00.000Z, when S3 finished processing the request, "eventName":"event-type", "userIdentity":{ "principalId":"Amazon-customer-ID-of-the-user-who-caused-the-event" }, "requestParameters":{ "sourceIPAddress":"ip-address-where-request-came-from" }, "responseElements":{ "x-amz-request-id":"Amazon S3 generated request ID", "x-amz-id-2":"Amazon S3 host that processed the request" }, "s3":{ "s3SchemaVersion":"1.0", "configurationId":"ID found in the bucket notification configuration", "bucket":{ "name":"bucket-name", "ownerIdentity":{ "principalId":"Amazon-customer-ID-of-the-bucket-owner" }, "arn":"bucket-ARN" }, "object":{ "key":"object-key", "size":object-size, "eTag":"object eTag", "versionId":"object version if bucket is versioning-enabled, otherwise null", "sequencer": "a string representation of a hexadecimal value used to determine event sequence, only used with PUTs and DELETEs" } } }, { // Additional events } ] }

以下是示例消息:

  • 测试消息 - 当您在存储桶上配置事件通知时,Amazon S3 会发送以下测试消息:

    Copy
    { "Service":"Amazon S3", "Event":"s3:TestEvent", "Time":"2014-10-13T15:57:02.089Z", "Bucket":"bucketname", "RequestId":"5582815E1AEA5ADF", "HostId":"8cLeGAmw098X5cv4Zkwcmo8vvZa3eH3eKxsPzbB9wrR+YstdA6Knx4Ip8EXAMPLE" }
  • 使用 PUT 请求创建对象时的示例消息 - 以下消息是 Amazon S3 发送以发布 s3:ObjectCreated:Put 事件的消息示例:

    Copy
    { "Records":[ { "eventVersion":"2.0", "eventSource":"aws:s3", "awsRegion":"us-east-1", "eventTime":"1970-01-01T00:00:00.000Z", "eventName":"ObjectCreated:Put", "userIdentity":{ "principalId":"AIDAJDPLRKLG7UEXAMPLE" }, "requestParameters":{ "sourceIPAddress":"127.0.0.1" }, "responseElements":{ "x-amz-request-id":"C3D13FE58DE4C810", "x-amz-id-2":"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD" }, "s3":{ "s3SchemaVersion":"1.0", "configurationId":"testConfigRule", "bucket":{ "name":"mybucket", "ownerIdentity":{ "principalId":"A3NL1KOZZKExample" }, "arn":"arn:aws-cn:s3:::mybucket" }, "object":{ "key":"HappyFace.jpg", "size":1024, "eTag":"d41d8cd98f00b204e9800998ecf8427e", "versionId":"096fKKXTRTtl3on89fVO.nfljtsv6qko", "sequencer":"0055AED6DCD90281E5" } } } ] }