clineamb / gulp-s3-upload

A gulp task to upload/update assets to an S3 account.
62 stars 37 forks source link

Add option for SSL #48

Open saadqc opened 7 years ago

saadqc commented 7 years ago

I am trying to upload static files to S3. It works with node 4.10 but throws following error with 8.1.2

here is the task

var s3 = require('gulp-s3-upload')(config.aws_credentials);

gulp.task("upload", function () {
  log('Syncing files with s3 bucket');
  gulp.src(config.build + '**/*')
    .pipe(s3({
      Bucket: config.bucket, //  Required
      ACL: 'public-read',       //  Needs to be user-defined,
      keyTransform: function (relative_filename) {
        var new_name = 'build/' + relative_filename;
        log(new_name);
        // or do whatever you want
        return new_name;
      }
    }, {
      // S3 Constructor Options, ie:
      maxRetries: 5
    }));
});

I am sure that I have access to S3. As I can update files with node 4.1.0 version. The issue with SSL. Can we simply put an option to use SSL or not? like in aws sdk we can use sslEnabled: false

[14:26:00] build/images/img/default/fancybox/fancybox_overlay.png
[14:26:00] build/images/img/default/fancybox/fancybox_sprite.png
/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/request.js:31
            throw err;
            ^

Error: S3 headObject Error: Error: Hostname/IP doesn't match certificate's altnames: "Host: sample2017-staging.s3.amazonaws.com. is not in the cert's altnames: DNS:*.s3.amazonaws.com, DNS:s3.amazonaws.com"
    at Object.checkServerIdentity (tls.js:221:17)
    at TLSSocket.<anonymous> (_tls_wrap.js:1104:29)
    at emitNone (events.js:105:13)
    at TLSSocket.emit (events.js:207:7)
    at TLSSocket._finishInit (_tls_wrap.js:628:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:458:38)
    at Request.callListeners (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/sequential_executor.js:107:43)
    at Request.emit (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/request.js:668:14)
    at Request.transition (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/request.js:670:12)
    at Request.callListeners (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/home/saad/PycharmProjects/sample/web-app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
clineamb commented 7 years ago

I'll take a look into this. I have somewhat dropped the ball and haven't made an update to the versions of this. Expect an update soon.

saadqc commented 7 years ago

Awesome! Thank You.

clineamb commented 7 years ago

@saadqc - Can you post the structure of your config.awscredentials?

By default, the initial constructor takes in SSLEnabled as per the AWS SDK: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html

So:

var s3      = require('gulp-s3-upload')({
    'accessKeyId': 'YOURACCESSKEYID',
    'secretAccessKey': 'YOURSECRET',
    'sslEnabled': true,
    /* any other necessary options to enable SSL */
});
saadqc commented 7 years ago

Here is the structure:

var aws_credentials= { 'accessKeyId': 'YOURACCESSKEYID', 'secretAccessKey': 'YOURSECRET' };

Regarding sslEnabled option. Yes, I set that to false/true but that didn't work in my case.

Also, few things that I tried to get it working but no luck with that too. process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; https://stackoverflow.com/a/21961005/2490859

Did you try on Node >= 8.0 version?