Add the ability to set KMSKeyArn to a Lambda function#356
Add the ability to set KMSKeyArn to a Lambda function#356DeviaVir merged 3 commits intomotdotla:masterfrom
Conversation
| 'Runtime': params.Runtime, | ||
| 'VpcConfig': params.VpcConfig, | ||
| 'Environment': params.Environment, | ||
| 'KMSKeyArn': params.KMSKeyArn, |
There was a problem hiding this comment.
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.
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.
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
| 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.
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.
DeviaVir
left a comment
There was a problem hiding this comment.
👍 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.