node.jsamazon-s3knox-amazon-s3-client

Turn on Server-side encryption and Get Object Version in Amazon S3 with knox and nodejs


So far I've been able to successfully use node.js, express, and knox to add/update/delete/retrieve objects in Amazon S3. Trying to move things to the next level I'm trying to figure out how to use knox (if it's possible) to do two things:

1) Set the object to use server-side encryption when adding/updating the object.

2) Get a particular version of an object or get a list of versions of the object.


Solution

  • Andy (who wrote AwsSum) here.

    Using AwsSum, when you put an object, just set the 'ServerSideEncryption' to the value you want (currently S3 only supports 'AES256'). Easy! :)

    e.g.

    var body = ...; // a buffer, a string, a stream
    
    var options = {
        BucketName    : 'chilts',
        ObjectName    : 'my-object.ext',
        ContentLength : Buffer.byteLength(body),
        Body          : body,
        ServerSideEncryption : 'AES256'
    };
    
    s3.PutObject(options, function(err, data) {
        console.log("\nputting an object to pie-18 - expecting success");
        console.log(err, 'Error');
        console.log(data, 'Data');
    });