Using the Node AWS-SDK with Riak-CS

I went through several hours of messing around with a couple of node modules that seemed to work but I had issues with so I ended up using the Node AWS-SDK as is.  Here’s some examples of a PUT, DELETE, and GET.

PUT


    fs.stat(parsedFile.path, function(err, file_info){
        if(err){
            throw err;
        }
        
        var AWS = require('aws-sdk');        
        var s3 = new AWS.S3({ 
            endpoint: "http://<host name without bucket prepended>", 
            accessKeyId: <accessKeyId>, 
            secretAccessKey: <secretAccessKey>
        });

        fs.readFile(<full path to file>, function(err, data) {
            if(err){
                throw err;
            }

            var params = {
                Bucket: <bucketName>,
                Key: <fileName>,
                Body: data
            };

            s3.putObject(params, function(err, result) {
                if(err){
                    throw err;
                }
            });
        });
    });

DELETE


    var AWS = require('aws-sdk');        
    var s3 = new AWS.S3({ 
        endpoint: "http://<host name without bucket prepended>", 
        accessKeyId: <accessKeyId>, 
        secretAccessKey: <secretAccessKey>
    });

    var params = {
        Bucket: <bucketName>,
        Key: <filename>,
    };

    s3.deleteObject(params, function(err, result) {
        if(err){
            throw err;
        }
    });
    

GET


    var AWS = require('aws-sdk');        
    var s3 = new AWS.S3({ 
        endpoint: "http://<host name without bucket prepended>", 
        accessKeyId: <accessKeyId>, 
        secretAccessKey: <secretAccessKey>
    });

    var params = {
        Bucket: <bucketName>,
        Key: <filename>,
    };
    
    // streaming from riak-cs to express response
    s3.getObject(params).createReadStream().pipe(res);

I hope this helps anyone else out there.