我想知道 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"
}
}
}
]
}
您可以使用以下方法将 JSON 解析为
S3EventNotification
类:
S3EventNotification eventNotification = S3EventNotification.parseJson(yourJsonString);
有了这个,您就可以从记录列表中获取
S3EventNotificationRecord
。