Skip to content

Instantly share code, notes, and snippets.

@fecori
Forked from sjehutch/index.js
Created March 12, 2019 19:22
Show Gist options
  • Select an option

  • Save fecori/937328f003172c344bf2c06a927b1be5 to your computer and use it in GitHub Desktop.

Select an option

Save fecori/937328f003172c344bf2c06a927b1be5 to your computer and use it in GitHub Desktop.

Revisions

  1. @sjehutch sjehutch created this gist Jun 2, 2018.
    17 changes: 17 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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.");
    }
    });
    };