From dc31eaa66b4fbd2e53b16d1938f20e002b7bc37f Mon Sep 17 00:00:00 2001 From: arturomartinez Date: Tue, 15 Mar 2016 15:47:53 +0100 Subject: [PATCH 1/2] Add VPC Support --- README.md | 14 ++++++++++++++ test/unit/date_facade_test.js | 6 +++--- test/unit/deploy_task_test.js | 28 +++++++++++++++++++++++++++- utils/deploy_task.js | 13 +++++++++++-- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d2fc5b5..1a16e52 100644 --- a/README.md +++ b/README.md @@ -416,6 +416,20 @@ alias will be created, allowing you to keep the old alias available for backward It is recommended that `enableVersioning` is also enabled when using this feature. +##### options.subnetIds +Type: `Array` +Default value: `null` + +A list of one or more subnet IDs in your VPC. + +##### options.securityGroupIds +Type: `Array` +Default value: `null` + +A list of one or more security groups IDs in your VPC. + +If your Lambda function accesses resources in a VPC you must provide at least one security group and one subnet ID. These must belong to the same VPC + #### Usage Examples ##### Default Options diff --git a/test/unit/date_facade_test.js b/test/unit/date_facade_test.js index 57446c1..82fc533 100644 --- a/test/unit/date_facade_test.js +++ b/test/unit/date_facade_test.js @@ -39,8 +39,8 @@ dateFacadeTest.testGetFormattedTimestamp = function(test) { }; dateFacadeTest.testGetHumanReadableTimestamp = function(test) { - var fixedDate = new Date(2016, 1, 13, 14, 38, 13); - test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('Sat Feb 13 2016 14:38:13') > -1); + var fixedDate = new Date(2016, 2, 13, 14, 38, 13); + test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('2016-03-13 14:38:13') > -1); test.done(); }; -module.exports = dateFacadeTest; \ No newline at end of file +module.exports = dateFacadeTest; diff --git a/test/unit/deploy_task_test.js b/test/unit/deploy_task_test.js index a2bd084..758c1d9 100644 --- a/test/unit/deploy_task_test.js +++ b/test/unit/deploy_task_test.js @@ -283,6 +283,32 @@ deployTaskTest.testMemorySize = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; +deployTaskTest.testVpcConfig = function(test) { + test.expect(4); + + var deployTask = require('../../utils/deploy_task'); + + var harnessParams = { + options: { + subnetIds: ['subnet-XXXXX'], + securityGroupIds: ['sg-XXXXXX'] + }, + 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({VpcConfig: { + SubnetIds : ['subnet-XXXXX'], + SecurityGroupIds : ['sg-XXXXXX'] + }})); + test.done(); + } + }; + gruntMock.execute(deployTask.getHandler, harnessParams); +}; + deployTaskTest.testHandler = function(test) { test.expect(4); @@ -468,4 +494,4 @@ deployTaskTest.testMultipleAliases = function(test) { gruntMock.execute(deployTask.getHandler, harnessParams); }; -module.exports = deployTaskTest; \ No newline at end of file +module.exports = deployTaskTest; diff --git a/utils/deploy_task.js b/utils/deploy_task.js index da028c7..70a5361 100644 --- a/utils/deploy_task.js +++ b/utils/deploy_task.js @@ -35,7 +35,9 @@ deployTask.getHandler = function (grunt) { handler: null, enableVersioning: false, aliases: null, - enablePackageVersionAlias: false + enablePackageVersionAlias: false, + subnetIds: null, + securityGroupIds: null }); if (options.profile !== null) { @@ -138,6 +140,13 @@ deployTask.getHandler = function (grunt) { configParams.Handler = options.handler; } + if (options.subnetIds !== null && options.securityGroupIds !== null) { + configParams.VpcConfig = { + SubnetIds : options.subnetIds, + SecurityGroupIds : options.securityGroupIds + }; + } + var updateConfig = function (func_name, func_options) { var deferred = Q.defer(); if (Object.keys(func_options).length > 0) { @@ -264,4 +273,4 @@ deployTask.getHandler = function (grunt) { }; }; -module.exports = deployTask; \ No newline at end of file +module.exports = deployTask; From d4e1fd17b9dc9096b96b14ba3a79e825995e4619 Mon Sep 17 00:00:00 2001 From: arturomartinez Date: Tue, 15 Mar 2016 16:04:17 +0100 Subject: [PATCH 2/2] Travis CI Fix --- test/unit/date_facade_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/date_facade_test.js b/test/unit/date_facade_test.js index 82fc533..45e710d 100644 --- a/test/unit/date_facade_test.js +++ b/test/unit/date_facade_test.js @@ -40,7 +40,7 @@ dateFacadeTest.testGetFormattedTimestamp = function(test) { dateFacadeTest.testGetHumanReadableTimestamp = function(test) { var fixedDate = new Date(2016, 2, 13, 14, 38, 13); - test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('2016-03-13 14:38:13') > -1); + test.ok(dateFacade.getHumanReadableTimestamp(fixedDate).indexOf('Sun Mar 13 2016 14:38:13') > -1); test.done(); }; module.exports = dateFacadeTest;