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

2.2k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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');
});
1
On

I know this is an old question, but it is possible to upload a file with knox using server-side encryption by specifying a header:

client.putFile('test.txt', '/test.txt', {"x-amz-server-side-encryption": "AES256"}, function(err, res) {
    //Do something here
});