-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add the ability to set KMSKeyArn to a Lambda function #356
Conversation
@@ -473,6 +476,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => { | |||
'Runtime': params.Runtime, | |||
'VpcConfig': params.VpcConfig, | |||
'Environment': params.Environment, | |||
'KMSKeyArn': params.KMSKeyArn, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
})
There was a problem hiding this comment.
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.
…KEY_ARN does not exist
@@ -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 || '' |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 - 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 :) |
@d3viant0ne yep, I'll publish a tag today. |
@d3viant0ne https://www.npmjs.com/package/node-lambda |
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.