From 73fa8c729ba4d80082ce5ed485537b298b1e545e Mon Sep 17 00:00:00 2001 From: Daniel Bradley Date: Wed, 8 Feb 2017 14:55:23 +0000 Subject: [PATCH] Add support for environment variables Fixes #24 --- README.md | 3 +++ index.js | 1 + test/all.js | 13 +++++++++++++ test/fake-lambda-service.js | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6078313..0073f35 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,9 @@ module.exports = { memorySize: 128, publish: true, // default: false, runtime: 'nodejs4.3', // default: 'nodejs4.3', + env: {, // optionl + [] + }, vpc: { // optional SecurityGroupIds: [, ...], SubnetIds: [, ...] diff --git a/index.js b/index.js index 773f76d..f3e7f5d 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,7 @@ exports.deploy = function(codePackage, config, callback, logger, lambda) { MemorySize: config.memorySize }; if (config.vpc) params.VpcConfig = config.vpc; + if (config.env) params.Environment = { Variables: config.env }; var isPublish = (config.publish === true); var updateEventSource = function(eventSource, callback) { diff --git a/test/all.js b/test/all.js index 71e909b..f05b897 100644 --- a/test/all.js +++ b/test/all.js @@ -28,6 +28,9 @@ describe('node aws lambda module', function() { timeout: 10, memorySize: 128, publish: true, + env: { + MyEvnVar: 'helloworld var', + }, vpc: { SecurityGroupIds: ['sg-xxxxxxx1', 'sg-xxxxxxx2'], SubnetIds: ['subnet-xxxxxxxx'] @@ -86,6 +89,11 @@ describe('node aws lambda module', function() { MemorySize: 128, Publish: true, Runtime: "nodejs4.3", + Environment: { + Variables : { + MyEvnVar: 'helloworld var' + } + }, VpcConfig: { SecurityGroupIds: ['sg-xxxxxxx1', 'sg-xxxxxxx2'], SubnetIds: ['subnet-xxxxxxxx'] @@ -142,6 +150,11 @@ describe('node aws lambda module', function() { MemorySize: 128, Publish: false, Runtime: "nodejs4.3", + Environment: { + Variables: { + MyEvnVar: 'helloworld var', + }, + }, VpcConfig: { SecurityGroupIds: ['sg-xxxxxxx3'], SubnetIds: ['subnet-xxxxxxx1', 'subnet-xxxxxxx2'] diff --git a/test/fake-lambda-service.js b/test/fake-lambda-service.js index cee6a9e..e879515 100644 --- a/test/fake-lambda-service.js +++ b/test/fake-lambda-service.js @@ -50,7 +50,7 @@ module.exports = function() { createFunction: function(params, callback) { validateParams(params, ['FunctionName', 'Code', 'Handler', 'Role', 'Runtime'], - ['Description', 'MemorySize', 'Timeout', 'Publish', 'VpcConfig'], 'createFunction') + ['Description', 'MemorySize', 'Timeout', 'Publish', 'VpcConfig', 'Environment'], 'createFunction') var name = params.FunctionName; var code = params.Code; @@ -154,7 +154,7 @@ module.exports = function() { updateFunctionConfiguration: function(params, callback) { validateParams(params, ['FunctionName'], - ['Description', 'Handler', 'MemorySize', 'Role', 'Timeout', 'VpcConfig'], + ['Description', 'Handler', 'MemorySize', 'Role', 'Timeout', 'VpcConfig', 'Environment'], 'updateFunctionConfiguration') var fun = getFun(params.FunctionName);