From 411866b69497e2bbf3ba54c007a9f19f5fbff8a2 Mon Sep 17 00:00:00 2001 From: Pascal Dubois Date: Fri, 10 Jun 2016 20:04:24 -0400 Subject: [PATCH] Added the credentials option --- README.md | 15 +++++++++++++++ index.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 09fd9b3..61cf11f 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,18 @@ Allows you to publish a new version when passing in a string for `lambda_params` #### `region = 'us-east-1'` Set your AWS region. + +#### `credentials` + +Allow to override the AWS object. For example, this could be useful is you need to provide credentials from alternate source. + +For example: +```js +AWS.config.loadFromPath('../aws.json'); +var awsCredentials = AWS.config.credentials; + +var opts = { + credentials: awsCredentials; +}; +``` +The `credentials` parameter will take precedence over the region one. diff --git a/index.js b/index.js index 50b0eb6..0ff58f3 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,9 @@ var DEFAULT_PARAMS = { Runtime: 'nodejs4.3' }; +var makeWarning = function(message) { + return gutil.log(gutil.colors.red(message)); +}; var makeErr = function(message) { return new gutil.PluginError('gulp-awslambda', message); @@ -67,12 +70,24 @@ module.exports = function(params, opts) { gutil.log('Uploading Lambda function "' + functionName + '"...'); + if (opts.profile && opts.config) { + return cb(makeWarning('Option "credentials" will take precedence over option "region"')); + } + if (opts.profile !== null) { AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: opts.profile }); } AWS.config.update({ region: opts.region }); + if (opts.credentials !== null) { + if (opts.credentials.constructor.name === 'Credentials') { + AWS.config.credentials = opts.credentials; + } else { + return cb(makeErr('Option `credentials` is not an instance of Credentials')); + } + } + var lambda = new AWS.Lambda(); var stream = this;