amazon-web-services - S3 - 从 Post S3 Upload lambda 函数获取元数据
问题描述
我正在使用s3.getSignedUrl('putObject', params)
and 为我的参数生成一个预签名的 URL
var params = {
Bucket: bucketName,
Key: photoId + "-" + photoNumber + "-of-" + numberImages + ".jpeg",
Expires: signedUrlExpireSeconds,
ContentType: contentType,
Metadata : { testkey1 : "hello" }
};
我试图在我的 S3 成功上传 lambda 函数中接收元数据,但它没有出现。有谁知道为什么?上传成功,对于我打印的日志,我收到了除元数据标签之外的所有内容:
console.log(event);
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "2020-01-15T06:51:57.171Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId":
},
"requestParameters": {
"sourceIPAddress":
},
"responseElements": {
"x-amz-request-id": "4C32689CE5B70A82",
"x-amz-id-2": "AS0f97RHlLW2DF6tVfRwbTeoEpk2bEne/0LrWqHpLJRHY5GMBjy/NQOHqYAMhd2JjiiUcuw0nUTMJS8pDAch1Abc5xzzWVMv"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "9a9a755e-e809-4dbf-abf8-3450aaa208ed",
"bucket": {
"name": ,
"ownerIdentity": {
"principalId": "A3SZPXLS03IWBG"
},
"arn":
},
"object": {
"key": "BcGMYe-1-of-1.jpeg",
"size": 19371,
"eTag": "45c719f2f6b5349cc360db9a13d0cee4",
"sequencer": "005E1EB6921E08F7E4"
}
}
}
]
解决方案
这是s3
事件消息结构。消息结构最初不包含元数据。
您需要亲自获取lambda
函数中的元数据。
如果收到事件,您将通过s3
head-object命令获取元数据。bucket-name
object-key
{
"Records":[
{
"eventVersion":"2.2",
"eventSource":"aws:s3",
"awsRegion":"us-west-2",
"eventTime":The time, in ISO-8601 format, for example, 1970-01-01T00:00:00.000Z, when Amazon 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"
}
},
"glacierEventData": {
"restoreEventData": {
"lifecycleRestorationExpiryTime": "The time, in ISO-8601 format, for example, 1970-01-01T00:00:00.000Z, of Restore Expiry",
"lifecycleRestoreStorageClass": "Source storage class for restore"
}
}
}
]
}
推荐阅读
- c# - 正确取消 Socket.XXXAsync 调用
- android - 错误':expo-permissions:debugCompileClasspath':找不到recyclerview-1.0.0.jar
- c# - 如何在 C# Rest 服务中从 Android 应用程序读取 JSON 数据
- rust - 在 Rust 中使用 warp 框架同时在多个端口(http、https)上服务
- core-data - SwiftUI 中的核心数据
- angular - 在 Angular 中使用带有 TypeScript 类型的 JavaScript 包
- angular - 是否可以在剑道角度网格中设置行号?
- r - 从期间列按年份子集数据
- java - 迭代时如何处理数组中的null
- node.js - 无法在视图目录 NestJs 中查找视图“索引”