node-lambda 0.21.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 +23 -5
- package/CHANGELOG.md +6 -0
- package/README.md +27 -0
- package/bin/node-lambda +3 -2
- package/lib/main.js +12 -2
- package/lib/s3_deploy.js +1 -0
- package/package.json +14 -14
- package/test/main.js +7 -3
- package/test/node-lambda.js +1 -0
- package/test/s3_deploy.js +1 -0
|
@@ -3,14 +3,13 @@ name: Node CI
|
|
|
3
3
|
on: [push, pull_request]
|
|
4
4
|
|
|
5
5
|
jobs:
|
|
6
|
-
test:
|
|
7
|
-
name: Test on node ${{ matrix.node-version }} and
|
|
8
|
-
runs-on:
|
|
6
|
+
ubuntu-test:
|
|
7
|
+
name: Test on node ${{ matrix.node-version }} and Ubuntu
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
9
|
strategy:
|
|
10
10
|
fail-fast: false
|
|
11
11
|
matrix:
|
|
12
|
-
node-version: [
|
|
13
|
-
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
12
|
+
node-version: [14.x, 16.x, 17.x]
|
|
14
13
|
steps:
|
|
15
14
|
- uses: actions/checkout@v2
|
|
16
15
|
- uses: actions/setup-node@v2
|
|
@@ -22,3 +21,22 @@ jobs:
|
|
|
22
21
|
- run: npm -v
|
|
23
22
|
- run: npm ci
|
|
24
23
|
- run: npm test
|
|
24
|
+
|
|
25
|
+
mac-and-windows-test:
|
|
26
|
+
name: Test on node latest and ${{ matrix.os }}
|
|
27
|
+
runs-on: ${{ matrix.os }}
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
os: [windows-latest, macos-latest]
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v2
|
|
34
|
+
- uses: actions/setup-node@v2
|
|
35
|
+
with:
|
|
36
|
+
node-version: 16.x
|
|
37
|
+
cache: 'npm'
|
|
38
|
+
- run: npm i -g npm
|
|
39
|
+
- run: node -v
|
|
40
|
+
- run: npm -v
|
|
41
|
+
- run: npm ci
|
|
42
|
+
- run: npm test
|
package/CHANGELOG.md
CHANGED
|
@@ -444,3 +444,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
444
444
|
## [0.21.0] - 2021-11-10
|
|
445
445
|
### Features
|
|
446
446
|
- feat: support for yarn [#581](https://github.com/motdotla/node-lambda/pull/581)
|
|
447
|
+
|
|
448
|
+
## [0.22.0] - 2022-02-17
|
|
449
|
+
### Features
|
|
450
|
+
- Support for Architectures parameter [#591](https://github.com/motdotla/node-lambda/pull/591)
|
|
451
|
+
### Bugfixes
|
|
452
|
+
- fix: skip installing the package, when there is no `package.json` [#589](https://github.com/motdotla/node-lambda/pull/589)
|
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ AWS_ROLE_ARN || AWS_ROLE // (default: 'missing')
|
|
|
81
81
|
AWS_MEMORY_SIZE // (default: 128)
|
|
82
82
|
AWS_TIMEOUT // (default: 60)
|
|
83
83
|
AWS_RUN_TIMEOUT // (default: 3)
|
|
84
|
+
AWS_ARCHITECTURE // (default: 'x86_64')
|
|
84
85
|
AWS_DESCRIPTION // (default: package.json.description or '')
|
|
85
86
|
AWS_RUNTIME // (default: 'nodejs14.x')
|
|
86
87
|
AWS_PUBLISH // (default: false)
|
|
@@ -179,6 +180,7 @@ Options:
|
|
|
179
180
|
-o, --role [AWS_ROLE] Amazon Role ARN (default: "missing")
|
|
180
181
|
-m, --memorySize [AWS_MEMORY_SIZE] Lambda Memory Size (default: 128)
|
|
181
182
|
-t, --timeout [AWS_TIMEOUT] Lambda Timeout (default: 60)
|
|
183
|
+
--architecture [AWS_ARCHITECTURE] The instruction set architecture that the function supports. (x86_64|arm64) (default: "x86_64")
|
|
182
184
|
-d, --description [AWS_DESCRIPTION] Lambda Description (default: "Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.")
|
|
183
185
|
-u, --runtime [AWS_RUNTIME] Lambda Runtime (default: "nodejs14.x")
|
|
184
186
|
-p, --publish [AWS_PUBLISH] Lambda Publish (default: false)
|
|
@@ -221,6 +223,31 @@ AWS Lambda will let you set environment variables for your function. Use the sam
|
|
|
221
223
|
|
|
222
224
|
AWS Lambda now supports Node.js14 and Node.js 12. Please also check the [Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) page.
|
|
223
225
|
|
|
226
|
+
## Use S3 to deploy
|
|
227
|
+
|
|
228
|
+
Use the command line argument `--deployUseS3` or `-B`. (This option is true/false.)
|
|
229
|
+
Example: `% node-lambda deploy -B`
|
|
230
|
+
|
|
231
|
+
You can also set the environment variable `DEPLOY_USE_S3`.
|
|
232
|
+
Example: `DEPLOY_USE_S3=true`
|
|
233
|
+
|
|
234
|
+
Use the environment variable to set the bucket name or S3 key prefix.
|
|
235
|
+
The environment variable name is different for each region. Please set it to the environment variable you want to deploy.
|
|
236
|
+
It can be set in `.env`.
|
|
237
|
+
|
|
238
|
+
Example:
|
|
239
|
+
|
|
240
|
+
```sh
|
|
241
|
+
# S3_<region>_BUCKET
|
|
242
|
+
S3_US_WEST_1_BUCKET=test_aaa
|
|
243
|
+
|
|
244
|
+
# S3_<region>_PREFIX
|
|
245
|
+
S3_US_WEST_1_PREFIX=bbb
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
In this case, the S3 key:
|
|
249
|
+
`test_aaa/bbb/deploy-package-${FunctionName}.zip`
|
|
250
|
+
|
|
224
251
|
## To deploy a container image to Lambda
|
|
225
252
|
|
|
226
253
|
1. [Pushing a Docker image to ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
|
package/bin/node-lambda
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
5
|
require('dotenv').config()
|
|
6
|
+
const process = require('process')
|
|
6
7
|
const path = require('path')
|
|
7
8
|
|
|
8
9
|
const lambda = require(path.join(__dirname, '..', 'lib', 'main.js'))
|
|
@@ -28,6 +29,7 @@ const AWS_ROLE = process.env.AWS_ROLE_ARN || process.env.AWS_ROLE || 'missing'
|
|
|
28
29
|
const AWS_MEMORY_SIZE = process.env.AWS_MEMORY_SIZE || 128
|
|
29
30
|
const AWS_TIMEOUT = process.env.AWS_TIMEOUT || 60
|
|
30
31
|
const AWS_RUN_TIMEOUT = process.env.AWS_RUN_TIMEOUT || 3
|
|
32
|
+
const AWS_ARCHITECTURE = process.env.AWS_ARCHITECTURE || 'x86_64'
|
|
31
33
|
const AWS_DESCRIPTION = process.env.AWS_DESCRIPTION || packageJson.description || ''
|
|
32
34
|
const AWS_RUNTIME = process.env.AWS_RUNTIME || 'nodejs14.x'
|
|
33
35
|
const AWS_PUBLISH = process.env.AWS_PUBLISH || false
|
|
@@ -62,8 +64,6 @@ const DOCKER_VOLUMES = process.env.DOCKER_VOLUMES || ''
|
|
|
62
64
|
const AWS_TAGS = process.env.AWS_TAGS || ''
|
|
63
65
|
const IMAGE_URI = process.env.IMAGE_URI || ''
|
|
64
66
|
|
|
65
|
-
program.showSuggestionAfterError()
|
|
66
|
-
|
|
67
67
|
program
|
|
68
68
|
.command('deploy')
|
|
69
69
|
.description('Deploy your application to Amazon Lambda')
|
|
@@ -82,6 +82,7 @@ program
|
|
|
82
82
|
.option('-o, --role [AWS_ROLE]', 'Amazon Role ARN', AWS_ROLE)
|
|
83
83
|
.option('-m, --memorySize [AWS_MEMORY_SIZE]', 'Lambda Memory Size', AWS_MEMORY_SIZE)
|
|
84
84
|
.option('-t, --timeout [AWS_TIMEOUT]', 'Lambda Timeout', AWS_TIMEOUT)
|
|
85
|
+
.option('--architecture [AWS_ARCHITECTURE]', 'The instruction set architecture that the function supports. (x86_64|arm64)', AWS_ARCHITECTURE)
|
|
85
86
|
.option('-d, --description [AWS_DESCRIPTION]', 'Lambda Description', AWS_DESCRIPTION)
|
|
86
87
|
.option('-u, --runtime [AWS_RUNTIME]', 'Lambda Runtime', AWS_RUNTIME)
|
|
87
88
|
.option('-p, --publish [AWS_PUBLISH]', 'Lambda Publish', AWS_PUBLISH)
|
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'))
|
|
@@ -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
|
|
@@ -429,6 +431,11 @@ Emulate only the body of the API Gateway event.
|
|
|
429
431
|
}
|
|
430
432
|
|
|
431
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
|
+
|
|
432
439
|
// Run on windows:
|
|
433
440
|
// https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
|
|
434
441
|
|
|
@@ -605,7 +612,8 @@ Emulate only the body of the API Gateway event.
|
|
|
605
612
|
async _uploadExisting (lambda, params) {
|
|
606
613
|
const functionCodeParams = Object.assign({
|
|
607
614
|
FunctionName: params.FunctionName,
|
|
608
|
-
Publish: params.Publish
|
|
615
|
+
Publish: params.Publish,
|
|
616
|
+
Architectures: params.Architectures
|
|
609
617
|
}, params.Code)
|
|
610
618
|
|
|
611
619
|
const functionConfigParams = {
|
|
@@ -729,7 +737,9 @@ they may not work as expected in the Lambda environment.
|
|
|
729
737
|
if (!program.keepNodeModules) {
|
|
730
738
|
console.log('=> Running package install')
|
|
731
739
|
const usedPackageManager = await this._packageInstall(program, codeDirectory)
|
|
732
|
-
|
|
740
|
+
if (usedPackageManager) {
|
|
741
|
+
console.log(`(Package manager used was '${usedPackageManager}'.)`)
|
|
742
|
+
}
|
|
733
743
|
}
|
|
734
744
|
await this._postInstallScript(program, codeDirectory)
|
|
735
745
|
console.log('=> Zipping deployment package')
|
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
|
-
"devDependencies": {
|
|
35
|
-
"aws-sdk-mock": "^5.2.1",
|
|
36
|
-
"chai": "^4.3.4",
|
|
37
|
-
"mocha": "^9.0.1",
|
|
38
|
-
"node-zip": "^1.1.1",
|
|
39
|
-
"standard": "^16.0.3"
|
|
40
|
-
},
|
|
41
34
|
"engines": {
|
|
42
35
|
"node": ">= 10.0.0"
|
|
43
36
|
},
|
|
44
37
|
"dependencies": {
|
|
45
38
|
"archiver": "^5.3.0",
|
|
46
|
-
"aws-sdk": "^2.
|
|
47
|
-
"aws-xray-sdk-core": "^3.3.
|
|
48
|
-
"commander": "^
|
|
39
|
+
"aws-sdk": "^2.1074.0",
|
|
40
|
+
"aws-xray-sdk-core": "^3.3.4",
|
|
41
|
+
"commander": "^9.0.0",
|
|
49
42
|
"continuation-local-storage": "^3.2.1",
|
|
50
|
-
"dotenv": "^
|
|
43
|
+
"dotenv": "^16.0.0",
|
|
51
44
|
"fs-extra": "^10.0.0",
|
|
52
|
-
"klaw": "^
|
|
53
|
-
"minimatch": "^
|
|
45
|
+
"klaw": "^4.0.1",
|
|
46
|
+
"minimatch": "^5.0.0",
|
|
54
47
|
"proxy-agent": "^5.0.0"
|
|
48
|
+
},
|
|
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
|
}
|
package/test/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 fs = require('fs-extra')
|
|
@@ -133,8 +134,8 @@ const _awsRestore = () => {
|
|
|
133
134
|
describe('lib/main', function () {
|
|
134
135
|
if (['win32', 'darwin'].includes(process.platform)) {
|
|
135
136
|
// It seems that it takes time for file operation in Windows and Mac.
|
|
136
|
-
// So set `timeout(
|
|
137
|
-
this.timeout(
|
|
137
|
+
// So set `timeout(120000)` for the whole test.
|
|
138
|
+
this.timeout(120000)
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
let aws = null // mock
|
|
@@ -150,7 +151,7 @@ describe('lib/main', function () {
|
|
|
150
151
|
})
|
|
151
152
|
|
|
152
153
|
it('version should be set', () => {
|
|
153
|
-
assert.equal(lambda.version, '0.
|
|
154
|
+
assert.equal(lambda.version, '0.22.0')
|
|
154
155
|
})
|
|
155
156
|
|
|
156
157
|
describe('_codeDirectory', () => {
|
|
@@ -740,6 +741,9 @@ describe('lib/main', function () {
|
|
|
740
741
|
const packageJson = require(packageJsonPath)
|
|
741
742
|
packageJson.optionalDependencies = { npm: '*' }
|
|
742
743
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson))
|
|
744
|
+
|
|
745
|
+
// Remove package-lock.json because it does not match the package.json to which optionalDependencies was added.
|
|
746
|
+
fs.removeSync(path.join(codeDirectory, 'package-lock.json'))
|
|
743
747
|
}
|
|
744
748
|
|
|
745
749
|
const testOptionalDependenciesIsInstalled = async (packageManager) => {
|
package/test/node-lambda.js
CHANGED