Skip to content

Instantly share code, notes, and snippets.

@sjehutch
Created June 2, 2018 14:26
Show Gist options
  • Select an option

  • Save sjehutch/902c88befb989ee561719f11f183416c to your computer and use it in GitHub Desktop.

Select an option

Save sjehutch/902c88befb989ee561719f11f183416c to your computer and use it in GitHub Desktop.
s3-copy-files-node
var AWS = require("aws-sdk");
exports.handler = (event, context, callback) => {
var s3 = new AWS.S3();
var sourceBucket = "SOURCE-BUCKET";
var destinationBucket = "DESTINATION-BUCKET";
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.");
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment