Skip to content Skip to sidebar Skip to footer

Aws-sdk S3 Upload Not Working From Mocha Test

Trying to run s3 upload from a mocha test: 'use strict'; describe('S3 test', function() { it.only('S3 test 1', function*() { var AWS = require('aws-sdk'); //AW

Solution 1:

Doh. Its asynchronous so I need to use the done callback:

'use strict';

describe('S3 test', function() {
    it.only('S3 test 1', function(done) {
        varAWS = require('aws-sdk');
        //AWS.config.region = 'us-west-2';var s3 = newAWS.S3({
            params: {
                Bucket: 'mkruk-myBucket',
                Key: 'myKey'
            }
        });
        s3.createBucket(function(err) {
            if (err) {
                console.log("Error:", err);
                done();
            } else {
                s3.upload({
                    Body: 'Hello!'
                }, function() {
                    console.log("Successfully uploaded data to myBucket/myKey");
                    done();
                });
            }
        });
    });
});

Solution 2:

may be missing accessKeyId and secretAccessKey

var s3 = new AWS.S3({
    accessKeyId: "",
    secretAccessKey: ""
});

then

s3.upload({
    Bucket: 'test-1-myBucket', 
    Key: 'myKey'
    Body: 'Hello!',    
}

Post a Comment for "Aws-sdk S3 Upload Not Working From Mocha Test"