Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/node-lambda
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''

@deekthesqueak deekthesqueak Jul 20, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KMSKeyArn will only clear with an empty string. If left undefined no change will be processed. With this change not including the environment variable will clear it.

There isn't a need to conditionally add it.

const AWS_DLQ_TARGET_ARN = (() => {
// You can clear the setting by passing an empty string
// when executing updateFunctionConfiguration
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Lambda.prototype._params = (program, buffer) => {
Environment: {
Variables: null
},
KMSKeyArn: program.kmsKeyArn,
DeadLetterConfig: {
TargetArn: null
},
Expand Down Expand Up @@ -473,6 +474,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => {
'Runtime': params.Runtime,
'VpcConfig': params.VpcConfig,
'Environment': params.Environment,
'KMSKeyArn': params.KMSKeyArn,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if I should include a conditional check here or not to add KMSKeyArn to the params.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a possible way to conditionally add it:

diff --git a/lib/main.js b/lib/main.js
index 3f5735e..9791c7e 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -466,7 +466,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => {
     }, (err) => {
       if (err) return reject(err)

-      lambda.updateFunctionConfiguration({
+      lambda.updateFunctionConfiguration(Object.assign({
         'FunctionName': params.FunctionName,
         'Description': params.Description,
         'Handler': params.Handler,
@@ -476,10 +476,10 @@ 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) => {
+      }, (typeof params.KMSKeyArn !== undefined) ? {'KMSKeyArn': params.KMSKeyArn}: {}),
+      (err, data) => {
         if (err) return reject(err)
         resolve(data)
       })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the only way to find that out is to test it. Sometimes the AWS SDK makes a problem from passing undefined parameters. I think the way your patch does it is the "safe" way and I would recommend updating it to that.

'DeadLetterConfig': params.DeadLetterConfig,
'TracingConfig': params.TracingConfig
}, (err, data) => {
Expand Down
13 changes: 13 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down