2
我是JavaScript新手,我正在嘗試編寫一個lambda函數,該函數會被bucket中的PUT事件觸發,函數會將s3對象中的文件名和一些元數據字段寫入dynamodb表。我大部分工作已經解決,但我堅持抓住x-amz-meta頭信息並將該變量傳遞給dynamo.put參數。任何人都可以告訴我我的代碼中做錯了什麼?謝謝!s3對象元數據lambda函數
var AWS = require('aws-sdk');
var dynamo = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
var s3 = new AWS.S3();
//specify the parameters from event to write to specified db table
exports.handler = function(event, context, callback) {
var srcKey = unescape(event.Records[0].s3.object.key);
var srcEtag = unescape(event.Records[0].s3.object.eTag);
var scrUploadTime = unescape(event.Records[0].eventTime);
var bucket= unescape(event.Records[0].s3.bucket.name);
var checksum =
s3.headObject(
{
Bucket: bucket,
Key: srcKey
},
function(err, data)
{
if (err)
{
console.log(err);
context.done('Error', 'Error getting s3 object: ' + err);
}
else
{
return console.log(this.httpResponse.headers['x-amz-meta-checksum']);
}
});
var params = {
Item: {
filename: srcKey,
uploadtime: scrUploadTime,
client_checksum : checksum
},
TableName: 'S3_log'
};
//write to dynammodb
dynamo.put(params, function(err, data){
if (err) {
callback(err, null);
}else{
callback(null, data);
}
});
};
這是什麼「return console.log(this.httpResponse.headers ['x-amz-meta-checksum']);」輸出?究竟是什麼問題? – Denis