Skip to content

Commit 6cc19b7

Browse files
committed
fix: use --lambdaVersion as alias name instead of appending to function name
fixes GH-849
1 parent e9f7ac5 commit 6cc19b7

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ AWS_ARCHITECTURE // (default: 'x86_64')
9494
AWS_DESCRIPTION // (default: package.json.description or '')
9595
AWS_RUNTIME // (default: 'nodejs16.x')
9696
AWS_PUBLISH // (default: false)
97-
AWS_FUNCTION_VERSION // (default: '')
97+
AWS_FUNCTION_VERSION // (default: '') When set, Publish is automatically enabled to create a version and alias.
9898
AWS_VPC_SUBNETS // (default: '')
9999
AWS_VPC_SECURITY_GROUPS // (default: '')
100100
AWS_TRACING_CONFIG // (default: '')
@@ -193,7 +193,7 @@ Options:
193193
-d, --description [AWS_DESCRIPTION] Lambda Description (default: "Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.")
194194
-u, --runtime [AWS_RUNTIME] Lambda Runtime (default: "nodejs16.x")
195195
-p, --publish [AWS_PUBLISH] Lambda Publish (default: false)
196-
-L, --lambdaVersion [AWS_FUNCTION_VERSION] Lambda Function Version (default: "")
196+
-L, --lambdaVersion [AWS_FUNCTION_VERSION] Lambda Function Version. Creates a version and alias. Automatically enables Publish. (default: "")
197197
-b, --vpcSubnets [AWS_VPC_SUBNETS] Lambda Function VPC Subnet IDs (comma delimited) (default: "")
198198
-g, --vpcSecurityGroups [AWS_VPC_SECURITY_GROUPS] Lambda VPC Security Group IDs (comma delimited) (default: "")
199199
-K, --kmsKeyArn [AWS_KMS_KEY_ARN] Lambda KMS Key ARN (default: "")

lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ Emulate only the body of the API Gateway event.
229229
_params (program, buffer) {
230230
const params = {
231231
FunctionName: program.functionName +
232-
(program.environment ? '-' + program.environment : '') +
233-
(program.lambdaVersion ? '-' + program.lambdaVersion : ''),
232+
(program.environment ? '-' + program.environment : ''),
234233
Code: {},
235234
Handler: program.handler,
236235
Role: program.role,
@@ -240,6 +239,7 @@ Emulate only the body of the API Gateway event.
240239
Timeout: program.timeout,
241240
Architectures: program.architecture ? [program.architecture] : ['x86_64'],
242241
Publish: (() => {
242+
if (program.lambdaVersion) return true
243243
if (typeof program.publish === 'boolean') {
244244
return program.publish
245245
}

test/main.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,18 @@ describe('lib/main', function () {
279279
assert.match(params.FunctionName, functionNamePattern)
280280
})
281281

282-
it('appends version to original functionName', () => {
282+
it('does not append version to functionName', () => {
283283
program.lambdaVersion = '2015-02-01'
284284
const params = lambda._params(program)
285-
assert.equal(params.FunctionName, '___node-lambda-development-2015-02-01')
285+
assert.equal(params.FunctionName, '___node-lambda-development')
286286
assert.match(params.FunctionName, functionNamePattern)
287287
})
288288

289-
it('appends version to original functionName (value not allowed by AWS)', () => {
290-
program.lambdaVersion = '2015.02.01'
289+
it('sets Publish to true when lambdaVersion is set', () => {
290+
program.lambdaVersion = 'v1'
291+
program.publish = false
291292
const params = lambda._params(program)
292-
assert.equal(params.FunctionName, '___node-lambda-development-2015_02_01')
293-
assert.match(params.FunctionName, functionNamePattern)
293+
assert.isTrue(params.Publish)
294294
})
295295

296296
it('appends VpcConfig to params when vpc params set', () => {
@@ -1682,11 +1682,10 @@ describe('lib/main', function () {
16821682
})
16831683
})
16841684

1685-
it('creates alias when publish and lambdaVersion are set', () => {
1686-
program.publish = true
1685+
it('creates alias when lambdaVersion is set', () => {
16871686
program.lambdaVersion = 'v1'
16881687
const params = lambda._params(program, null)
1689-
params.Publish = true
1688+
assert.isTrue(params.Publish)
16901689
return lambda._deployToRegion(program, params, 'us-east-1').then((result) => {
16911690
assert.equal(result.length, 4)
16921691
assert.deepEqual(result[3], lambdaMockSettings.updateAlias)

0 commit comments

Comments
 (0)