Copying Objects in S3 From One Bucket to Another Automatically w/ AWS Lambda https://www.aaronmedacco.com/blog/post/2017/01/11/copying-objects-in-s3-from-one-bucket-to-another-automatically-w-aws-lambda
var AWS = require("aws-sdk");
exports.handler = (event, context, callback) => {
var s3 = new AWS.S3();
var sourceBucket = "Source Bucket Name";
var destinationBucket = "Destination Bucket Name";
var objectKey = event.Records[0].s3.object.key;
var copySource = encodeURI(sourceBucket + "/" + objectKey);
var copyParams = { Bucket: destinationBucket, CopySource: copySource, Key: objectKey };
s3.copyObject(copyParams, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log("S3 object copy successful.");
}
});
};
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"Your Source Bucket ARN/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"Your Destination Bucket ARN/*"
]
}
]
}