Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional AWS Credentials and Region #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@ var archiver = require('archiver');
var async = require('async');
var AWS = require('aws-sdk');
var fs = require('fs');
var s3 = require('s3');
var s3 = require('@auth0/s3');

function S3Zipper(awsConfig) {
var self = this
assert.ok(awsConfig, 'AWS S3 options must be defined.');
assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.');
assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret');
assert.notEqual(awsConfig.region, undefined, 'Requires AWS S3 region.');
assert.notEqual(awsConfig.bucket, undefined, 'Requires AWS S3 bucket.');

AWS.config.update({
accessKeyId: awsConfig.accessKeyId,
secretAccessKey: awsConfig.secretAccessKey,
region: awsConfig.region
});

/* region is optional in order to use lambda's region */
awsConfig.region = awsConfig.region ? awsConfig.region : AWS.config.region;
if(!awsConfig.accessKeyId && !awsConfig.secretAccessKey){
/*
accessKey & secretAccessKey must be optional in order to use grants associated to the lambda function through IAM service
*/
AWS.config.update({
region: awsConfig.region
});
}else{
assert.notEqual(awsConfig.accessKeyId, undefined, 'Requires S3 AWS Key.');
assert.notEqual(awsConfig.secretAccessKey, undefined, 'Requires S3 AWS Secret');
AWS.config.update({
accessKeyId: awsConfig.accessKeyId,
secretAccessKey: awsConfig.secretAccessKey,
region: awsConfig.region
});
}
self.init(awsConfig);
}


function listObjectInner() {

}


S3Zipper.prototype = {
init: function (awsConfig) {
this.awsConfig = awsConfig;
Expand Down Expand Up @@ -112,6 +115,11 @@ S3Zipper.prototype = {
}
});

emitter.on('error', function(err) {
console.error('unable to get files:', err.stack);
callback(err);
});

emitter.on('end', function () {
var data = files;
console.log('end');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"archiver": "0.21.*",
"async": "1.5.*",
"aws-sdk": "2.2.*",
"s3": "latest"
"@auth0/s3": "latest"
},
"repository": "https://github.com/DanielHindi/aws-s3-zipper.git",
"keywords": [
Expand Down
Loading