SDK 中 AWS S3 到 SQS 事件的 Java 类

问题描述 投票:0回答:1

我想知道 aws-sdk 或 spring-cloud-aws 中是否有任何现成的 java 类用于标准 SQS 事件(如 S3“ObjectCreated:Put”),或者我是否需要自己创建它们。

我没有找到任何示例,所有示例似乎都使用非常简单的事件体,但也许我是盲目的。

我正在谈论的示例:

{
  "Records": [
    {
      "eventVersion": "2.1",
      "eventSource": "aws:s3",
      "awsRegion": "eu-central-1",
      "eventTime": "2024-04-19T08:43:56.425Z",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "AWS:AKJSDGHJKAHSDKJAASD"
      },
      "requestParameters": {
        "sourceIPAddress": "92.79.75.114"
      },
      "responseElements": {
        "x-amz-request-id": "JIOFAHJNEWJDFNASD",
        "x-amz-id-2": "lvTSuzcW9K77xJUIuSTn3d7B6Hz3dqw4KNd8Fc3tsMiA8g9P+B+9JoBKkUZC0aSB1Xm/7US7i/fHSfBPfuiZSgEwUumlYpaL"
      },
      "s3": {
        "s3SchemaVersion": "1.0",
        "configurationId": "demo-s3-to-sqs",
        "bucket": {
          "name": "upload-demo-123123123",
          "ownerIdentity": {
            "principalId": "ASJKDHNASDJKLASD"
          },
          "arn": "arn:aws:s3:::upload-demo-42342312"
        },
        "object": {
          "key": "123123/mydocument.pdf",
          "size": 11977091,
          "eTag": "cf8580c55a4babf566976531bfd467d8",
          "sequencer": "0066222ECC27CC73BA"
        }
      }
    }
  ]
}
java spring-boot aws-sdk amazon-sqs spring-cloud-aws
1个回答
0
投票

您可以使用以下方法将 JSON 解析为

S3EventNotification
类:

S3EventNotification eventNotification = S3EventNotification.parseJson(yourJsonString);

有了这个,您就可以从记录列表中获取

S3EventNotificationRecord

基于:https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/event/S3EventNotification.html#parseJson-java.lang.String-

© www.soinside.com 2019 - 2024. All rights reserved.