From 6ee3641ab0dfc16fe31d1db67e51511f22f2ddec Mon Sep 17 00:00:00 2001 From: Derek Bonner Date: Thu, 13 Jul 2017 19:29:34 -0700 Subject: [PATCH 1/3] Add the ability to set KMSKeyArn to a Lambda function --- bin/node-lambda | 2 ++ lib/main.js | 4 ++++ test/main.js | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/bin/node-lambda b/bin/node-lambda index 088a6036..3e000d89 100755 --- a/bin/node-lambda +++ b/bin/node-lambda @@ -43,6 +43,7 @@ const SRC_DIRECTORY = process.env.SRC_DIRECTORY || '' const DEPLOY_TIMEOUT = process.env.DEPLOY_TIMEOUT || 120000 const DOCKER_IMAGE = process.env.DOCKER_IMAGE || '' const DEPLOY_ZIPFILE = process.env.DEPLOY_ZIPFILE || '' +const AWS_KMS_KEY_ARN = process.env.AWS_KMS_KEY_ARN const AWS_DLQ_TARGET_ARN = (() => { // You can clear the setting by passing an empty string // when executing updateFunctionConfiguration @@ -76,6 +77,7 @@ program .option('-b, --vpcSubnets [' + AWS_VPC_SUBNETS + ']', 'Lambda Function VPC Subnets', AWS_VPC_SUBNETS) .option('-g, --vpcSecurityGroups [' + AWS_VPC_SECURITY_GROUPS + ']', 'Lambda VPC Security Group', AWS_VPC_SECURITY_GROUPS) + .option('-K, --kmsKeyArn [' + AWS_KMS_KEY_ARN + ']', 'Lambda KMS Key ARN', AWS_KMS_KEY_ARN) .option('-Q, --deadLetterConfigTargetArn [' + AWS_DLQ_TARGET_ARN + ']', 'Lambda DLQ resource', AWS_DLQ_TARGET_ARN) .option('-T, --tracingConfig [' + AWS_TRACING_CONFIG + ']', 'Lambda tracing settings', diff --git a/lib/main.js b/lib/main.js index a4cb32df..3f5735e2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -201,6 +201,9 @@ Lambda.prototype._params = (program, buffer) => { Variables: config } } + if (program.kmsKeyArn !== undefined) { + params.KMSKeyArn = program.kmsKeyArn + } if (program.deadLetterConfigTargetArn !== undefined) { params.DeadLetterConfig = { TargetArn: program.deadLetterConfigTargetArn @@ -473,6 +476,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => { 'Runtime': params.Runtime, 'VpcConfig': params.VpcConfig, 'Environment': params.Environment, + 'KMSKeyArn': params.KMSKeyArn, 'DeadLetterConfig': params.DeadLetterConfig, 'TracingConfig': params.TracingConfig }, (err, data) => { diff --git a/test/main.js b/test/main.js index 7239c5fe..7657b476 100644 --- a/test/main.js +++ b/test/main.js @@ -196,6 +196,19 @@ describe('lib/main', function () { assert.equal(Object.keys(params.VpcConfig.SecurityGroupIds).length, 0) }) + it('appends KMSKeyArn to params when KMS params set', () => { + ['', 'arn:aws:kms:test'].forEach((v) => { + program.kmsKeyArn = v + const params = lambda._params(program) + assert.equal(params.KMSKeyArn, v, v) + }) + }) + + it('does not append KMSKeyArn when params are not set', () => { + const params = lambda._params(program) + assert.isUndefined(params.KMSKeyArn) + }) + it('appends DeadLetterConfig to params when DLQ params set', () => { ['', 'arn:aws:sqs:test'].forEach((v) => { program.deadLetterConfigTargetArn = v From 21eff32177cc5aeede888198f819d65fd0433c04 Mon Sep 17 00:00:00 2001 From: Derek Bonner Date: Wed, 19 Jul 2017 18:50:29 -0700 Subject: [PATCH 2/3] Set default paramter to empty string to unset KMSKeyArn when AWS_KMS_KEY_ARN does not exist --- bin/node-lambda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node-lambda b/bin/node-lambda index 3e000d89..9e91b8a0 100755 --- a/bin/node-lambda +++ b/bin/node-lambda @@ -43,7 +43,7 @@ const SRC_DIRECTORY = process.env.SRC_DIRECTORY || '' const DEPLOY_TIMEOUT = process.env.DEPLOY_TIMEOUT || 120000 const DOCKER_IMAGE = process.env.DOCKER_IMAGE || '' const DEPLOY_ZIPFILE = process.env.DEPLOY_ZIPFILE || '' -const AWS_KMS_KEY_ARN = process.env.AWS_KMS_KEY_ARN +const AWS_KMS_KEY_ARN = process.env.AWS_KMS_KEY_ARN || '' const AWS_DLQ_TARGET_ARN = (() => { // You can clear the setting by passing an empty string // when executing updateFunctionConfiguration From 16043c19f4bc149157f09055cacf9d0bdd37246b Mon Sep 17 00:00:00 2001 From: Derek Bonner Date: Wed, 19 Jul 2017 19:18:57 -0700 Subject: [PATCH 3/3] With default paramter set the check against undefined is not needed --- lib/main.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3f5735e2..49e900fb 100644 --- a/lib/main.js +++ b/lib/main.js @@ -176,6 +176,7 @@ Lambda.prototype._params = (program, buffer) => { Environment: { Variables: null }, + KMSKeyArn: program.kmsKeyArn, DeadLetterConfig: { TargetArn: null }, @@ -201,9 +202,6 @@ Lambda.prototype._params = (program, buffer) => { Variables: config } } - if (program.kmsKeyArn !== undefined) { - params.KMSKeyArn = program.kmsKeyArn - } if (program.deadLetterConfigTargetArn !== undefined) { params.DeadLetterConfig = { TargetArn: program.deadLetterConfigTargetArn