diff --git a/lib/cfn.js b/lib/cfn.js index 21e7e15..56fac19 100644 --- a/lib/cfn.js +++ b/lib/cfn.js @@ -5,10 +5,13 @@ const fs = require('fs'); function hash2ArrayHash(hash, keyProperty = 'Key', valueProperty = 'Value') { return Object.keys(hash) - .map(key => ({ - [keyProperty]: key, - [valueProperty]: hash[key] - })); + .map(key => { + return hash[key] !== undefined ? { + [keyProperty]: key, + [valueProperty]: hash[key] + } : undefined; + }) + .filter(Boolean); } function ucFirst(str) { @@ -116,6 +119,10 @@ class CfnClient { let value = options[origKey]; let key = ucFirst(origKey); + if (value === undefined) { + return; + } + switch (origKey) { case 'parameters': value = hash2ArrayHash(value, 'ParameterKey', 'ParameterValue'); diff --git a/tests/unit/cfn-test.js b/tests/unit/cfn-test.js index 7133fd9..407198c 100644 --- a/tests/unit/cfn-test.js +++ b/tests/unit/cfn-test.js @@ -23,7 +23,8 @@ const options = { templateBody: `file://${templatePath}`, parameters: { key1: 'val1', - key2: 'val2' + key2: 'val2', + key3: undefined }, capabilities: ['CAPABILITY_IAM'], resourceTypes: ['AWS::*'], @@ -38,7 +39,8 @@ const options = { disableRollback: true, rollbackConfiguration: { MonitoringTimeInMinutes: 10 - } + }, + dummy: undefined }; const templateBody = fs.readFileSync(templatePath, { encoding: 'utf8' });