0
我在Lambda中有一個函數,只有在對象發生更改時纔會將元數據標題添加到s3上的對象。AWS Lambda函數和S3 - 僅當對象發生更改時才更改S3中的對象的元數據
ContentType: 'application/javascript'
CacheControl: 'max-age=600'
但事實證明,LAMBDA檢查大約100倍桶在秒,不僅如果對象改變了,其成本了很多。
訪問日誌上S3:
b6234e2652b93344f7 aa [02/Mar/2016:11:00:55 +0000] 54.0.0.209 arn:aws:sts::718436:assumed-role/lambda_s3_exec_role/awslambda_642_201609 805 REST.COPY.OBJECT /local.js "PUT /local.js HTTP/1.1" 200 - 234 4404 50 24 "-" "aws-sdk-nodejs/2.2.32 linux/v0.10.36" -
b6234ee5f9cf0344f7 aa [02/Mar/2016:11:00:55 +0000] 54.0.0.209 arn:aws:sts::71836:assumed-role/lambda_s3_exec_role/awslambda_642_209 890005 REST.COPY.OBJECT_GET local.js - 200 - - 4404 - - - - -
功能:
console.log('Loading function');
var aws = require('aws-sdk');
var s3 = new aws.S3({ apiVersion: '2006-03-01' });
exports.handler = function(event, context) {
//console.log('Received event:', JSON.stringify(event, null, 2));
// Get the object from the event and show its content type
var bucket = event.Records[0].s3.bucket.name;
var key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
var params = {
Bucket: bucket,
Key: key,
CopySource: encodeURIComponent(bucket+"/"+key),
ContentType: 'application/javascript',
CacheControl: 'max-age=600',
"Metadata":{
},
MetadataDirective: 'REPLACE'
};
//s3.getObject(params, function(err, data) {
s3.copyObject(params, function(err, data) {
if (err) {
console.log(err);
var message = "Error getting object " + key + " from bucket " + bucket +
". Make sure they exist and your bucket is in the same region as this function.";
console.log(message);
context.fail(message);
} else {
console.log('CONTENT TYPE:', data.ContentType);
context.succeed(data.ContentType);
}
});
};
我需要改變,以便在功能WIL什麼l只有當對象在s3中改變時才工作?
感謝先進!
'while(+1){...}'heh。一個建議是隻獲取對象元數據 - 而不是整個對象。 –