Skip to content

Commit 1472843

Browse files
deekthesqueakDeviaVir
authored andcommitted
Add the ability to set KMSKeyArn to a Lambda function (#356)
* Add the ability to set KMSKeyArn to a Lambda function * Set default paramter to empty string to unset KMSKeyArn when AWS_KMS_KEY_ARN does not exist * With default paramter set the check against undefined is not needed
1 parent a045af4 commit 1472843

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

bin/node-lambda

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const SRC_DIRECTORY = process.env.SRC_DIRECTORY || ''
4343
const DEPLOY_TIMEOUT = process.env.DEPLOY_TIMEOUT || 120000
4444
const DOCKER_IMAGE = process.env.DOCKER_IMAGE || ''
4545
const DEPLOY_ZIPFILE = process.env.DEPLOY_ZIPFILE || ''
46+
const AWS_KMS_KEY_ARN = process.env.AWS_KMS_KEY_ARN || ''
4647
const AWS_DLQ_TARGET_ARN = (() => {
4748
// You can clear the setting by passing an empty string
4849
// when executing updateFunctionConfiguration
@@ -76,6 +77,7 @@ program
7677
.option('-b, --vpcSubnets [' + AWS_VPC_SUBNETS + ']', 'Lambda Function VPC Subnets', AWS_VPC_SUBNETS)
7778
.option('-g, --vpcSecurityGroups [' + AWS_VPC_SECURITY_GROUPS + ']', 'Lambda VPC Security Group',
7879
AWS_VPC_SECURITY_GROUPS)
80+
.option('-K, --kmsKeyArn [' + AWS_KMS_KEY_ARN + ']', 'Lambda KMS Key ARN', AWS_KMS_KEY_ARN)
7981
.option('-Q, --deadLetterConfigTargetArn [' + AWS_DLQ_TARGET_ARN + ']', 'Lambda DLQ resource',
8082
AWS_DLQ_TARGET_ARN)
8183
.option('-T, --tracingConfig [' + AWS_TRACING_CONFIG + ']', 'Lambda tracing settings',

lib/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Lambda.prototype._params = (program, buffer) => {
176176
Environment: {
177177
Variables: null
178178
},
179+
KMSKeyArn: program.kmsKeyArn,
179180
DeadLetterConfig: {
180181
TargetArn: null
181182
},
@@ -473,6 +474,7 @@ Lambda.prototype._uploadExisting = (lambda, params) => {
473474
'Runtime': params.Runtime,
474475
'VpcConfig': params.VpcConfig,
475476
'Environment': params.Environment,
477+
'KMSKeyArn': params.KMSKeyArn,
476478
'DeadLetterConfig': params.DeadLetterConfig,
477479
'TracingConfig': params.TracingConfig
478480
}, (err, data) => {

test/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ describe('lib/main', function () {
196196
assert.equal(Object.keys(params.VpcConfig.SecurityGroupIds).length, 0)
197197
})
198198

199+
it('appends KMSKeyArn to params when KMS params set', () => {
200+
['', 'arn:aws:kms:test'].forEach((v) => {
201+
program.kmsKeyArn = v
202+
const params = lambda._params(program)
203+
assert.equal(params.KMSKeyArn, v, v)
204+
})
205+
})
206+
207+
it('does not append KMSKeyArn when params are not set', () => {
208+
const params = lambda._params(program)
209+
assert.isUndefined(params.KMSKeyArn)
210+
})
211+
199212
it('appends DeadLetterConfig to params when DLQ params set', () => {
200213
['', 'arn:aws:sqs:test'].forEach((v) => {
201214
program.deadLetterConfigTargetArn = v

0 commit comments

Comments
 (0)