Created
June 2, 2018 14:26
-
-
Save sjehutch/902c88befb989ee561719f11f183416c to your computer and use it in GitHub Desktop.
s3-copy-files-node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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