node-lambda 0.19.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/workflow.yml +26 -7
- package/.travis.yml +2 -0
- package/CHANGELOG.md +25 -0
- package/README.md +96 -67
- package/bin/node-lambda +6 -6
- package/lib/main.js +122 -79
- package/lib/s3_deploy.js +1 -0
- package/package.json +18 -18
- package/test/main.js +325 -123
- package/test/node-lambda.js +1 -0
- package/test/s3_deploy.js +1 -0
package/lib/main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const process = require('process')
|
|
3
4
|
const path = require('path')
|
|
4
5
|
const os = require('os')
|
|
5
6
|
const aws = require(path.join(__dirname, 'aws'))
|
|
@@ -51,7 +52,7 @@ event_sources.json and ${program.eventFile} files as needed.`)
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
run (program) {
|
|
54
|
-
if (!['
|
|
55
|
+
if (!['nodejs12.x', 'nodejs14.x'].includes(program.runtime)) {
|
|
55
56
|
console.error(`Runtime [${program.runtime}] is not supported.`)
|
|
56
57
|
process.exit(254)
|
|
57
58
|
}
|
|
@@ -215,6 +216,7 @@ Emulate only the body of the API Gateway event.
|
|
|
215
216
|
Description: program.description,
|
|
216
217
|
MemorySize: program.memorySize,
|
|
217
218
|
Timeout: program.timeout,
|
|
219
|
+
Architectures: program.architecture ? [program.architecture] : ['x86_64'],
|
|
218
220
|
Publish: (() => {
|
|
219
221
|
if (typeof program.publish === 'boolean') {
|
|
220
222
|
return program.publish
|
|
@@ -385,31 +387,73 @@ Emulate only the body of the API Gateway event.
|
|
|
385
387
|
return fs.existsSync(path.join(codeDirectory, 'package-lock.json'))
|
|
386
388
|
}
|
|
387
389
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
// https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
|
|
391
|
-
|
|
392
|
-
const installCommand = this._shouldUseNpmCi(codeDirectory)
|
|
393
|
-
? 'ci'
|
|
394
|
-
: 'install'
|
|
395
|
-
const npmInstallBaseOptions = [
|
|
390
|
+
_getNpmInstallCommand (program, codeDirectory) {
|
|
391
|
+
const installOptions = [
|
|
396
392
|
'-s',
|
|
397
|
-
|
|
393
|
+
this._shouldUseNpmCi(codeDirectory) ? 'ci' : 'install',
|
|
398
394
|
'--production',
|
|
399
395
|
'--no-audit'
|
|
400
396
|
]
|
|
401
397
|
|
|
402
398
|
if (program.optionalDependencies === false) {
|
|
403
|
-
|
|
399
|
+
installOptions.push('--no-optional')
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (!program.dockerImage) {
|
|
403
|
+
installOptions.push('--prefix', codeDirectory)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
packageManager: 'npm',
|
|
408
|
+
installOptions
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
_getYarnInstallCommand (program, codeDirectory) {
|
|
413
|
+
const installOptions = [
|
|
414
|
+
'-s',
|
|
415
|
+
'install',
|
|
416
|
+
'--production'
|
|
417
|
+
]
|
|
418
|
+
|
|
419
|
+
if (program.optionalDependencies === false) {
|
|
420
|
+
installOptions.push('--ignore-optional')
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (!program.dockerImage) {
|
|
424
|
+
installOptions.push('--cwd', codeDirectory)
|
|
404
425
|
}
|
|
405
426
|
|
|
427
|
+
return {
|
|
428
|
+
packageManager: 'yarn',
|
|
429
|
+
installOptions
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
_packageInstall (program, codeDirectory) {
|
|
434
|
+
if (!fs.existsSync(path.join(codeDirectory, 'package.json'))) {
|
|
435
|
+
console.log('Skip the installation of the package. (Because package.json is not found.)')
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Run on windows:
|
|
440
|
+
// https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
|
|
441
|
+
|
|
442
|
+
const { packageManager, installOptions } = (() => {
|
|
443
|
+
// default npm
|
|
444
|
+
if (program.packageManager === 'yarn') {
|
|
445
|
+
return this._getYarnInstallCommand(program, codeDirectory)
|
|
446
|
+
}
|
|
447
|
+
return this._getNpmInstallCommand(program, codeDirectory)
|
|
448
|
+
})()
|
|
449
|
+
|
|
406
450
|
const paramsOnContainer = (() => {
|
|
407
451
|
// with docker
|
|
408
452
|
let dockerVolumesOptions = []
|
|
409
453
|
program.dockerVolumes && program.dockerVolumes.split(' ').forEach((volume) => {
|
|
410
454
|
dockerVolumesOptions = dockerVolumesOptions.concat(['-v', volume])
|
|
411
455
|
})
|
|
412
|
-
const dockerCommand = [program.dockerImage,
|
|
456
|
+
const dockerCommand = [program.dockerImage, packageManager].concat(installOptions)
|
|
413
457
|
const dockerBaseOptions = [
|
|
414
458
|
'run', '--rm',
|
|
415
459
|
'-v', `${fs.realpathSync(codeDirectory)}:/var/task`,
|
|
@@ -429,17 +473,16 @@ Emulate only the body of the API Gateway event.
|
|
|
429
473
|
})()
|
|
430
474
|
|
|
431
475
|
const paramsOnHost = (() => {
|
|
432
|
-
// simple
|
|
433
|
-
const options = npmInstallBaseOptions.concat(['--prefix', codeDirectory])
|
|
476
|
+
// simple install
|
|
434
477
|
if (process.platform === 'win32') {
|
|
435
478
|
return {
|
|
436
479
|
command: 'cmd.exe',
|
|
437
|
-
options: ['/c',
|
|
480
|
+
options: ['/c', packageManager].concat(installOptions)
|
|
438
481
|
}
|
|
439
482
|
}
|
|
440
483
|
return {
|
|
441
|
-
command:
|
|
442
|
-
options
|
|
484
|
+
command: packageManager,
|
|
485
|
+
options: installOptions
|
|
443
486
|
}
|
|
444
487
|
})()
|
|
445
488
|
|
|
@@ -450,7 +493,7 @@ Emulate only the body of the API Gateway event.
|
|
|
450
493
|
env: process.env
|
|
451
494
|
}, (err) => {
|
|
452
495
|
if (err) return reject(err)
|
|
453
|
-
resolve()
|
|
496
|
+
resolve(packageManager)
|
|
454
497
|
})
|
|
455
498
|
})
|
|
456
499
|
}
|
|
@@ -518,7 +561,7 @@ Emulate only the body of the API Gateway event.
|
|
|
518
561
|
|
|
519
562
|
_codeDirectory () {
|
|
520
563
|
// Why realpathSync?:
|
|
521
|
-
// If tmpdir is symbolic link and npm>=7, `this.
|
|
564
|
+
// If tmpdir is symbolic link and npm>=7, `this._packageInstall()` may not work properly.
|
|
522
565
|
return path.join(fs.realpathSync(os.tmpdir()), `${path.basename(path.resolve('.'))}-lambda`)
|
|
523
566
|
}
|
|
524
567
|
|
|
@@ -530,28 +573,27 @@ Emulate only the body of the API Gateway event.
|
|
|
530
573
|
resolve()
|
|
531
574
|
})
|
|
532
575
|
})
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
576
|
+
}
|
|
577
|
+
return new Promise((resolve, reject) => {
|
|
578
|
+
fs.readdir(codeDirectory, (err, files) => {
|
|
579
|
+
if (err) return reject(err)
|
|
537
580
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
581
|
+
Promise.all(files.map(file => {
|
|
582
|
+
return new Promise((resolve, reject) => {
|
|
583
|
+
if (keepNodeModules && file === 'node_modules') {
|
|
584
|
+
resolve()
|
|
585
|
+
} else {
|
|
586
|
+
fs.remove(path.join(codeDirectory, file), err => {
|
|
587
|
+
if (err) return reject(err)
|
|
541
588
|
resolve()
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
if (err) return reject(err)
|
|
545
|
-
resolve()
|
|
546
|
-
})
|
|
547
|
-
}
|
|
548
|
-
})
|
|
549
|
-
})).then(() => {
|
|
550
|
-
resolve()
|
|
589
|
+
})
|
|
590
|
+
}
|
|
551
591
|
})
|
|
592
|
+
})).then(() => {
|
|
593
|
+
resolve()
|
|
552
594
|
})
|
|
553
595
|
})
|
|
554
|
-
}
|
|
596
|
+
})
|
|
555
597
|
}
|
|
556
598
|
|
|
557
599
|
_setRunTimeEnvironmentVars (program) {
|
|
@@ -567,10 +609,11 @@ Emulate only the body of the API Gateway event.
|
|
|
567
609
|
}
|
|
568
610
|
}
|
|
569
611
|
|
|
570
|
-
_uploadExisting (lambda, params) {
|
|
612
|
+
async _uploadExisting (lambda, params) {
|
|
571
613
|
const functionCodeParams = Object.assign({
|
|
572
614
|
FunctionName: params.FunctionName,
|
|
573
|
-
Publish: params.Publish
|
|
615
|
+
Publish: params.Publish,
|
|
616
|
+
Architectures: params.Architectures
|
|
574
617
|
}, params.Code)
|
|
575
618
|
|
|
576
619
|
const functionConfigParams = {
|
|
@@ -595,29 +638,30 @@ Emulate only the body of the API Gateway event.
|
|
|
595
638
|
delete functionConfigParams.Layers
|
|
596
639
|
}
|
|
597
640
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams, (err) => {
|
|
605
|
-
if (err) return reject(err)
|
|
606
|
-
resolve(configResponse)
|
|
607
|
-
})
|
|
641
|
+
const updateConfigRequest = lambda.updateFunctionConfiguration(functionConfigParams)
|
|
642
|
+
updateConfigRequest.on('retry', (response) => {
|
|
643
|
+
console.log(response.error.message)
|
|
644
|
+
console.log('=> Retrying')
|
|
645
|
+
})
|
|
646
|
+
const updateConfigResponse = await updateConfigRequest.promise()
|
|
608
647
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
648
|
+
// Wait for the `Configuration.LastUpdateStatus` to change from `InProgress` to `Successful`.
|
|
649
|
+
for (let i = 0; i < 10; i++) {
|
|
650
|
+
const data = await lambda.getFunction({ FunctionName: params.FunctionName }).promise()
|
|
651
|
+
if (data.Configuration.LastUpdateStatus === 'Successful') {
|
|
652
|
+
break
|
|
653
|
+
}
|
|
654
|
+
await new Promise((resolve) => setTimeout(resolve, 3000))
|
|
655
|
+
}
|
|
615
656
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
657
|
+
const updateCodeRequest = lambda.updateFunctionCode(functionCodeParams)
|
|
658
|
+
updateCodeRequest.on('retry', (response) => {
|
|
659
|
+
console.log(response.error.message)
|
|
660
|
+
console.log('=> Retrying')
|
|
620
661
|
})
|
|
662
|
+
await updateCodeRequest.promise()
|
|
663
|
+
|
|
664
|
+
return updateConfigResponse
|
|
621
665
|
}
|
|
622
666
|
|
|
623
667
|
_uploadNew (lambda, params) {
|
|
@@ -658,13 +702,17 @@ Emulate only the body of the API Gateway event.
|
|
|
658
702
|
_archivePrebuilt (program) {
|
|
659
703
|
const codeDirectory = this._codeDirectory()
|
|
660
704
|
|
|
661
|
-
return
|
|
662
|
-
|
|
663
|
-
|
|
705
|
+
return Promise.resolve().then(() => {
|
|
706
|
+
return this._cleanDirectory(codeDirectory, program.keepNodeModules)
|
|
707
|
+
}).then(() => {
|
|
708
|
+
return this._fileCopy(program, program.prebuiltDirectory, codeDirectory, false).then(() => {
|
|
709
|
+
console.log('=> Zipping deployment package')
|
|
710
|
+
return this._zip(program, codeDirectory)
|
|
711
|
+
})
|
|
664
712
|
})
|
|
665
713
|
}
|
|
666
714
|
|
|
667
|
-
_buildAndArchive (program) {
|
|
715
|
+
async _buildAndArchive (program) {
|
|
668
716
|
if (!fs.existsSync('.env')) {
|
|
669
717
|
console.warn('[Warning] `.env` file does not exist.')
|
|
670
718
|
console.info('Execute `node-lambda setup` as necessary and set it up.')
|
|
@@ -683,24 +731,19 @@ they may not work as expected in the Lambda environment.
|
|
|
683
731
|
const codeDirectory = this._codeDirectory()
|
|
684
732
|
const lambdaSrcDirectory = program.sourceDirectory ? program.sourceDirectory.replace(/\/$/, '') : '.'
|
|
685
733
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
if (
|
|
693
|
-
|
|
694
|
-
} else {
|
|
695
|
-
console.log(`=> Running npm ${this._shouldUseNpmCi(codeDirectory) ? 'ci' : 'install'} --production`)
|
|
696
|
-
return this._npmInstall(program, codeDirectory)
|
|
734
|
+
await this._cleanDirectory(codeDirectory, program.keepNodeModules)
|
|
735
|
+
console.log('=> Moving files to temporary directory')
|
|
736
|
+
await this._fileCopy(program, lambdaSrcDirectory, codeDirectory, true)
|
|
737
|
+
if (!program.keepNodeModules) {
|
|
738
|
+
console.log('=> Running package install')
|
|
739
|
+
const usedPackageManager = await this._packageInstall(program, codeDirectory)
|
|
740
|
+
if (usedPackageManager) {
|
|
741
|
+
console.log(`(Package manager used was '${usedPackageManager}'.)`)
|
|
697
742
|
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
return this._zip(program, codeDirectory)
|
|
703
|
-
})
|
|
743
|
+
}
|
|
744
|
+
await this._postInstallScript(program, codeDirectory)
|
|
745
|
+
console.log('=> Zipping deployment package')
|
|
746
|
+
return this._zip(program, codeDirectory)
|
|
704
747
|
}
|
|
705
748
|
|
|
706
749
|
_listEventSourceMappings (lambda, params) {
|
package/lib/s3_deploy.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-lambda",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.",
|
|
5
5
|
"main": "lib/main.js",
|
|
6
6
|
"directories": {
|
|
@@ -31,26 +31,26 @@
|
|
|
31
31
|
"readmeFilename": "README.md",
|
|
32
32
|
"author": "motdotla",
|
|
33
33
|
"license": "BSD-2-Clause",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"chai": "^4.2.0",
|
|
37
|
-
"mocha": "^8.2.1",
|
|
38
|
-
"node-zip": "^1.1.1",
|
|
39
|
-
"standard": "^16.0.1"
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">= 10.0.0"
|
|
40
36
|
},
|
|
41
37
|
"dependencies": {
|
|
42
|
-
"archiver": "^5.
|
|
43
|
-
"aws-sdk": "^2.
|
|
44
|
-
"aws-xray-sdk-core": "^3.
|
|
45
|
-
"commander": "^
|
|
38
|
+
"archiver": "^5.3.0",
|
|
39
|
+
"aws-sdk": "^2.1074.0",
|
|
40
|
+
"aws-xray-sdk-core": "^3.3.4",
|
|
41
|
+
"commander": "^9.0.0",
|
|
46
42
|
"continuation-local-storage": "^3.2.1",
|
|
47
|
-
"dotenv": "^
|
|
48
|
-
"fs-extra": "^
|
|
49
|
-
"klaw": "^
|
|
50
|
-
"minimatch": "^
|
|
51
|
-
"proxy-agent": "^
|
|
43
|
+
"dotenv": "^16.0.0",
|
|
44
|
+
"fs-extra": "^10.0.0",
|
|
45
|
+
"klaw": "^4.0.1",
|
|
46
|
+
"minimatch": "^5.0.0",
|
|
47
|
+
"proxy-agent": "^5.0.0"
|
|
52
48
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"aws-sdk-mock": "^5.6.2",
|
|
51
|
+
"chai": "^4.3.6",
|
|
52
|
+
"mocha": "^9.2.0",
|
|
53
|
+
"node-zip": "^1.1.1",
|
|
54
|
+
"standard": "^16.0.4"
|
|
55
55
|
}
|
|
56
56
|
}
|