mardi 28 juillet 2015

"Missing credentials in config" while trying to stream a file to Amazon S3 bucket in node.js

I tried to setup a basic file stream to Amazon S3. I copied and pasted the example on http://ift.tt/1Kw78xu

And modified it slightly (as attached).

   var AWS = require('aws-sdk'),
   zlib = require('zlib'),
   s = require('fs');
   s3Stream = require('s3-upload-stream')(new AWS.S3()),

        // Set the client to be used for the upload.
        AWS.config.loadFromPath('./config.json');


    // Create the streams
    var read = fs.createReadStream('path to a file');
    var compress = zlib.createGzip();
    var upload = s3Stream.upload({
        "Bucket": "bucketName",
        "Key": "file.txt"
    });

    module.exports = function (router) {
        router.get('/', function (req, res) {
            res.render('upload')
        })
        router.post('/', function (req, res) {
            // Handle errors.
            upload.on('error', function (error) {
                console.log(error);
            });


            /* Handle progress. Example details object:
             { ETag: '"f9ef956c83756a80ad62f54ae5e7d34b"',
             PartNumber: 5,
             receivedSize: 29671068,
             uploadedSize: 29671068 }
             */
            upload.on('part', function (details) {
                console.log(details);
            });


            /* Handle upload completion. Example details object:
             { Location: 'http://ift.tt/1ONpOHJ',
             Bucket: 'bucketName',
             Key: 'filename.ext',
             ETag: '"bf2acbedf84207d696c8da7dbb205b9f-5"' }
             */
            upload.on('uploaded', function (details) {
                console.log(details);
            });

            // Pipe the incoming filestream through compression, and up to S3.
            read.pipe(compress).pipe(upload);

        })

    }

My config file is setup like so:

{
 "accessKeyId": "key",
 "secretAccessKey":"secret",
 "region": "us-east-1e"
}

The code returns the following error:

    Failed to create a multipart upload on S3 : 
        {
            "message":"Missing credentials in config",
            "code":"CredentialsError",
            "time":"2015-07-28T22:59:10.763Z",
            "originalError":
                {
                    "message":"Could not load credentials from any providers",
                    "code":"CredentialsError",
                    "time":"2015-07-28T22:59:10.763Z",
                    "originalError":
                        {
                            "message": "Connection timed out after 1000ms",
                            "code":"TimeoutError",
                            "time":"2015-07-28T22:59:10.762Z"
                        }
                }
        }

To solve this I tried hard-coding the credentials using

AWS.config.update

Which doesn't seem to work as well.

What could the reason be for the error?

Thanks all!




Aucun commentaire:

Enregistrer un commentaire