From 6bd602d6c23dea3120b0c4e2476a894535276ffb Mon Sep 17 00:00:00 2001 From: Teddy Newell <teddynewell@icloud.com> Date: Wed, 23 Nov 2016 03:52:48 -0800 Subject: [PATCH 1/3] Added environment variables to function configuration --- test/unit/deploy_task_test.js | 30 ++++++++++++++++++++++++++++++ utils/deploy_task.js | 10 ++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/test/unit/deploy_task_test.js b/test/unit/deploy_task_test.js index d584f18..3b7141b 100644 --- a/test/unit/deploy_task_test.js +++ b/test/unit/deploy_task_test.js @@ -365,6 +365,36 @@ deployTaskTest.testVpcConfig = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; +deployTaskTest.testEnvironmentVariables = function(test) { + test.expect(4); + + var deployTask = require('../../utils/deploy_task'); + + var harnessParams = { + options: { + environmentVariables: { + "key-1": "value-1", + "key-2": "value-2" + } + }, + config: defaultGruntConfig, + callback: function(harness) { + test.equal(harness.status, true); + test.equal(harness.output.length, 3); + test.equal(harness.output[2], 'Config updated.'); + + test.ok(lambdaAPIMock.updateFunctionConfiguration.calledWithMatch({Environment: { + Variables: { + "key-1": "value-1", + "key-2": "value-2" + } + }})); + test.done(); + } + }; + gruntMock.execute(deployTask.getHandler, harnessParams); +}; + deployTaskTest.testHandler = function(test) { test.expect(4); diff --git a/utils/deploy_task.js b/utils/deploy_task.js index fd6c675..f879ad8 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -39,9 +39,10 @@ deployTask.getHandler = function (grunt) { aliases: null, enablePackageVersionAlias: false, subnetIds: null, - securityGroupIds: null + securityGroupIds: null, + environmentVariables: null }); - + if (options.profile !== null) { var credentials = new AWS.SharedIniFileCredentials({profile: options.profile}); AWS.config.credentials = credentials; @@ -149,6 +150,11 @@ deployTask.getHandler = function (grunt) { configParams.Handler = options.handler; } + if (options.environmentVariables !== null) { + Variables: options.environmentVariables + }; + } + if (options.subnetIds !== null && options.securityGroupIds !== null) { configParams.VpcConfig = { SubnetIds : options.subnetIds, From 1950e1ad8925baa8247d18cb887922c23275e41c Mon Sep 17 00:00:00 2001 From: Teddy Newell <teddynewell@icloud.com> Date: Wed, 23 Nov 2016 03:56:50 -0800 Subject: [PATCH 2/3] Added missing line --- utils/deploy_task.js | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/deploy_task.js b/utils/deploy_task.js index f879ad8..24e8821 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -151,6 +151,7 @@ deployTask.getHandler = function (grunt) { } if (options.environmentVariables !== null) { + configParams.Environment = { Variables: options.environmentVariables }; } From dc5a4c24d08611a8e731762c325bbf0c8e83067f Mon Sep 17 00:00:00 2001 From: Teddy Newell <teddynewell@icloud.com> Date: Wed, 23 Nov 2016 04:07:35 -0800 Subject: [PATCH 3/3] Updated aws-sdk dependency version To support environment variables, use aws-sdk version >= 2.7.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aa9e517..9ca0ff9 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "mkdirp": "~0.5.0", "rimraf": "~2.2.8", "glob": "~4.3.0", - "aws-sdk": "~2.2.32", + "aws-sdk": "~2.7.5", "proxy-agent": "latest", "npm": "^2.10.0", "q": "^1.4.1"