ラムダトリガーでamazon s3でファイルを移動する際に問題が発生します。 私はs3.getObject
を行うことができるが、私はあなたが唯一のバケット間でファイルを移動する場合イムs3.putObject
同じアマゾンアカウントのバケット間でファイルを移動する
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
var s3params = {Bucket: srcBucket, Key: srcKey};
s3.getObject(s3params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log("Loaded " + data.ContentLength + " bytes"); // successful response
var destinationpath = destinationbucket + '/moved_files/';
console.log("Destination: " +destinationpath);
var destiniation_name = destinationpath + str.split("/")[3];
console.log(destiniation_name);
var upparams = {Bucket: destinationbucket, Key: destiniation_name,ContentType: data.ContentType, Body: data.Stream};
s3.putObject(upparams,function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log("upload response " +data); // successful response
context.succeed('exit');
});
});
ファイルの内容を変更せずにあるバケットから別のバケットにコピーを行っているだけの場合は、そのファイルを 'copyObject'メソッドで直接行うことができます。それ以外の場合は、エラーメッセージを表示します。 –