Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set KMSKeyArn to a Lambda function #356

Merged
merged 3 commits into from
Jul 20, 2017

Conversation

deekthesqueak
Copy link
Contributor

The AWS SDK has the ability to set the KMSKeyArn when creating a Lambda function.
https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html

This PR adds the ability to set the KMSKeyArn. By default the value is not included in the params.

@@ -473,6 +476,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => {
'Runtime': params.Runtime,
'VpcConfig': params.VpcConfig,
'Environment': params.Environment,
'KMSKeyArn': params.KMSKeyArn,
Copy link
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
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
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.

@DeviaVir DeviaVir self-requested a review July 19, 2017 11:53
@@ -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 || ''
Copy link
Contributor Author

@deekthesqueak deekthesqueak Jul 20, 2017

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.

Copy link
Collaborator

@DeviaVir DeviaVir left a comment

Choose a reason for hiding this comment

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

👍 thanks for taking to time to add this!

@DeviaVir DeviaVir merged commit 1472843 into motdotla:master Jul 20, 2017
@joshwiens
Copy link

joshwiens commented Sep 22, 2017

@DeviaVir - Any chance you could tag / publish a minor off of master, we could of course run off a hash from git but in this case the addition above is going straight to prod & I would prefer to not have to go the git repo route as a version in a prod app. Thanks :)

@DeviaVir
Copy link
Collaborator

@d3viant0ne yep, I'll publish a tag today.

@DeviaVir DeviaVir mentioned this pull request Sep 22, 2017
@DeviaVir
Copy link
Collaborator

@d3viant0ne https://www.npmjs.com/package/node-lambda 0.11.4 now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants