node-lambda 1.3.0 → 2.0.0-alpha.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 +2 -2
- package/README.md +1 -1
- package/bin/node-lambda +1 -1
- package/lib/.env.example +1 -0
- package/lib/aws.js +41 -38
- package/lib/cloudwatch_logs.js +22 -32
- package/lib/main.js +142 -168
- package/lib/s3_deploy.js +18 -24
- package/lib/s3_events.js +16 -27
- package/lib/schedule_events.js +21 -35
- package/package.json +12 -9
- package/tea.yaml +6 -0
- package/test/cloudwatch_logs.js +17 -13
- package/test/main.js +92 -60
- package/test/node-lambda.js +17 -6
- package/test/s3_deploy.js +15 -15
- package/test/s3_events.js +15 -17
- package/test/schedule_events.js +15 -17
package/lib/s3_events.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { S3Client, PutBucketNotificationConfigurationCommand } = require('@aws-sdk/client-s3')
|
|
4
|
+
const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Do not create S3 bucket.
|
|
5
8
|
* Put the Notification Configuration in the existing Bucket.
|
|
6
9
|
*/
|
|
7
10
|
class S3Events {
|
|
8
|
-
constructor (
|
|
9
|
-
|
|
10
|
-
this.
|
|
11
|
-
region,
|
|
12
|
-
apiVersion: '2015-03-31'
|
|
13
|
-
})
|
|
14
|
-
this.s3 = new aws.S3({
|
|
15
|
-
region,
|
|
16
|
-
apiVersion: '2006-03-01'
|
|
17
|
-
})
|
|
11
|
+
constructor (config) {
|
|
12
|
+
this.s3Client = new S3Client(config)
|
|
13
|
+
this.lambdaClient = new LambdaClient(config)
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
_functionName (params) {
|
|
@@ -36,17 +32,14 @@ class S3Events {
|
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
_addPermission (params) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
resolve(data)
|
|
48
|
-
})
|
|
49
|
-
})
|
|
35
|
+
const _params = this._addPermissionParams(params)
|
|
36
|
+
try {
|
|
37
|
+
return this.lambdaClient.send(new AddPermissionCommand(_params))
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err.code !== 'ResourceConflictException') throw err
|
|
40
|
+
// If it exists it will result in an error but there is no problem.
|
|
41
|
+
return 'Permission already set'
|
|
42
|
+
}
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
_lambdaFunctionConfiguration (params) {
|
|
@@ -86,12 +79,8 @@ class S3Events {
|
|
|
86
79
|
}
|
|
87
80
|
|
|
88
81
|
_putBucketNotificationConfiguration (putBucketNotificationConfigurationParams) {
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
if (err) reject(err)
|
|
92
|
-
resolve(data)
|
|
93
|
-
})
|
|
94
|
-
})
|
|
82
|
+
return this.s3Client.send(
|
|
83
|
+
new PutBucketNotificationConfigurationCommand(putBucketNotificationConfigurationParams))
|
|
95
84
|
}
|
|
96
85
|
|
|
97
86
|
add (paramsList) {
|
package/lib/schedule_events.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { CloudWatchEventsClient, PutRuleCommand, PutTargetsCommand } = require('@aws-sdk/client-cloudwatch-events')
|
|
4
|
+
const { LambdaClient, AddPermissionCommand } = require('@aws-sdk/client-lambda')
|
|
5
|
+
|
|
3
6
|
class ScheduleEvents {
|
|
4
|
-
constructor (
|
|
5
|
-
|
|
6
|
-
this.
|
|
7
|
-
region,
|
|
8
|
-
apiVersion: '2015-03-31'
|
|
9
|
-
})
|
|
10
|
-
this.cloudwatchevents = new aws.CloudWatchEvents({
|
|
11
|
-
apiVersion: '2015-10-07'
|
|
12
|
-
})
|
|
7
|
+
constructor (config) {
|
|
8
|
+
this.cweClient = new CloudWatchEventsClient(config)
|
|
9
|
+
this.lambdaClient = new LambdaClient(config)
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
_ruleDescription (params) {
|
|
@@ -34,13 +31,9 @@ class ScheduleEvents {
|
|
|
34
31
|
|
|
35
32
|
_putRule (params) {
|
|
36
33
|
// return RuleArn if created
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (err) reject(err)
|
|
41
|
-
resolve(rule)
|
|
42
|
-
})
|
|
43
|
-
})
|
|
34
|
+
return this.cweClient.send(
|
|
35
|
+
new PutRuleCommand(this._putRulePrams(params))
|
|
36
|
+
)
|
|
44
37
|
}
|
|
45
38
|
|
|
46
39
|
_addPermissionParams (params) {
|
|
@@ -54,17 +47,14 @@ class ScheduleEvents {
|
|
|
54
47
|
}
|
|
55
48
|
|
|
56
49
|
_addPermission (params) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
resolve(data)
|
|
66
|
-
})
|
|
67
|
-
})
|
|
50
|
+
const _params = this._addPermissionParams(params)
|
|
51
|
+
try {
|
|
52
|
+
return this.lambdaClient.send(new AddPermissionCommand(_params))
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (err.code !== 'ResourceConflictException') throw err
|
|
55
|
+
// If it exists it will result in an error but there is no problem.
|
|
56
|
+
return 'Permission already set'
|
|
57
|
+
}
|
|
68
58
|
}
|
|
69
59
|
|
|
70
60
|
_putTargetsParams (params) {
|
|
@@ -79,14 +69,10 @@ class ScheduleEvents {
|
|
|
79
69
|
}
|
|
80
70
|
|
|
81
71
|
_putTargets (params) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
if (err) reject(err)
|
|
87
|
-
resolve(data)
|
|
88
|
-
})
|
|
89
|
-
})
|
|
72
|
+
// even if it is already registered, it will not be an error.
|
|
73
|
+
return this.cweClient.send(
|
|
74
|
+
new PutTargetsCommand(this._putTargetsParams(params))
|
|
75
|
+
)
|
|
90
76
|
}
|
|
91
77
|
|
|
92
78
|
add (params) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-lambda",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.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": {
|
|
@@ -32,23 +32,26 @@
|
|
|
32
32
|
"author": "motdotla",
|
|
33
33
|
"license": "BSD-2-Clause",
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">= 18.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"aws-sdk": "^
|
|
38
|
+
"@aws-sdk/client-cloudwatch-events": "^3.797.0",
|
|
39
|
+
"@aws-sdk/client-cloudwatch-logs": "^3.782.0",
|
|
40
|
+
"@aws-sdk/client-lambda": "^3.670.0",
|
|
41
|
+
"@aws-sdk/client-s3": "^3.782.0",
|
|
42
|
+
"@dotenvx/dotenvx": "^1.14.0",
|
|
43
|
+
"archiver": "^7.0.0",
|
|
40
44
|
"aws-xray-sdk-core": "^3.5.0",
|
|
41
|
-
"commander": "^
|
|
45
|
+
"commander": "^12.0.0",
|
|
42
46
|
"continuation-local-storage": "^3.2.1",
|
|
43
|
-
"dotenv": "^16.0.3",
|
|
44
47
|
"fs-extra": "^11.1.1",
|
|
45
48
|
"klaw": "^4.1.0",
|
|
46
|
-
"minimatch": "^
|
|
49
|
+
"minimatch": "^10.0.1",
|
|
47
50
|
"proxy-agent": "^6.2.0"
|
|
48
51
|
},
|
|
49
52
|
"devDependencies": {
|
|
50
|
-
"aws-sdk-mock": "^
|
|
51
|
-
"chai": "^
|
|
53
|
+
"aws-sdk-client-mock": "^4.1.0",
|
|
54
|
+
"chai": "^5.0.0",
|
|
52
55
|
"mocha": "^10.1.0",
|
|
53
56
|
"node-zip": "^1.1.1",
|
|
54
57
|
"standard": "^17.0.0"
|
package/tea.yaml
ADDED
package/test/cloudwatch_logs.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let assert
|
|
4
|
+
import('chai').then(chai => {
|
|
5
|
+
assert = chai.assert
|
|
6
|
+
})
|
|
4
7
|
const path = require('path')
|
|
5
|
-
const aws = require('aws-sdk-mock')
|
|
6
|
-
aws.setSDK(path.resolve('node_modules/aws-sdk'))
|
|
7
8
|
const CloudWatchLogs = require(path.join('..', 'lib', 'cloudwatch_logs'))
|
|
8
9
|
|
|
10
|
+
const {
|
|
11
|
+
CloudWatchLogsClient,
|
|
12
|
+
CreateLogGroupCommand,
|
|
13
|
+
PutRetentionPolicyCommand
|
|
14
|
+
} = require('@aws-sdk/client-cloudwatch-logs')
|
|
15
|
+
const { mockClient } = require('aws-sdk-client-mock')
|
|
16
|
+
const mockCloudWatchLogsClient = mockClient(CloudWatchLogsClient)
|
|
17
|
+
|
|
9
18
|
const mockResponse = {
|
|
10
19
|
createLogGroup: {
|
|
11
20
|
testCreateLogGroupResponse: 'An empty object is returned in the actual API'
|
|
@@ -23,21 +32,16 @@ const params = {
|
|
|
23
32
|
|
|
24
33
|
let logs = null
|
|
25
34
|
|
|
26
|
-
/* global before,
|
|
35
|
+
/* global before, describe, it */
|
|
27
36
|
describe('lib/cloudwatch_logs', () => {
|
|
28
37
|
before(() => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
aws.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
|
|
33
|
-
callback(null, mockResponse.putRetentionPolicy)
|
|
34
|
-
})
|
|
38
|
+
mockCloudWatchLogsClient.reset()
|
|
39
|
+
mockCloudWatchLogsClient.on(CreateLogGroupCommand).resolves(mockResponse.createLogGroup)
|
|
40
|
+
mockCloudWatchLogsClient.on(PutRetentionPolicyCommand).resolves(mockResponse.putRetentionPolicy)
|
|
35
41
|
|
|
36
|
-
logs = new CloudWatchLogs(
|
|
42
|
+
logs = new CloudWatchLogs({ region: 'us-east-1' })
|
|
37
43
|
})
|
|
38
44
|
|
|
39
|
-
after(() => aws.restore('CloudWatchLogs'))
|
|
40
|
-
|
|
41
45
|
describe('_logGroupName', () => {
|
|
42
46
|
it('correct value', () => {
|
|
43
47
|
assert.equal(
|
package/test/main.js
CHANGED
|
@@ -7,9 +7,52 @@ const fs = require('fs-extra')
|
|
|
7
7
|
const { execFileSync } = require('child_process')
|
|
8
8
|
const lambda = require(path.join(__dirname, '..', 'lib', 'main'))
|
|
9
9
|
const Zip = require('node-zip')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
let assert
|
|
11
|
+
import('chai').then(chai => {
|
|
12
|
+
assert = chai.assert
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const { mockClient } = require('aws-sdk-client-mock')
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
LambdaClient,
|
|
19
|
+
AddPermissionCommand,
|
|
20
|
+
CreateEventSourceMappingCommand,
|
|
21
|
+
CreateFunctionCommand,
|
|
22
|
+
DeleteEventSourceMappingCommand,
|
|
23
|
+
GetFunctionCommand,
|
|
24
|
+
ListEventSourceMappingsCommand,
|
|
25
|
+
ListTagsCommand,
|
|
26
|
+
TagResourceCommand,
|
|
27
|
+
UntagResourceCommand,
|
|
28
|
+
UpdateEventSourceMappingCommand,
|
|
29
|
+
UpdateFunctionCodeCommand,
|
|
30
|
+
UpdateFunctionConfigurationCommand
|
|
31
|
+
} = require('@aws-sdk/client-lambda')
|
|
32
|
+
const mockLambdaClient = mockClient(LambdaClient)
|
|
33
|
+
const lambdaClient = new LambdaClient({ region: 'us-east-1' })
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
CloudWatchLogsClient,
|
|
37
|
+
CreateLogGroupCommand,
|
|
38
|
+
PutRetentionPolicyCommand
|
|
39
|
+
} = require('@aws-sdk/client-cloudwatch-logs')
|
|
40
|
+
const mockCloudWatchLogsClient = mockClient(CloudWatchLogsClient)
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
CloudWatchEventsClient,
|
|
44
|
+
PutRuleCommand,
|
|
45
|
+
PutTargetsCommand
|
|
46
|
+
} = require('@aws-sdk/client-cloudwatch-events')
|
|
47
|
+
const mockCloudWatchEventsClient = mockClient(CloudWatchEventsClient)
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
S3Client,
|
|
51
|
+
CreateBucketCommand,
|
|
52
|
+
PutBucketNotificationConfigurationCommand,
|
|
53
|
+
PutObjectCommand
|
|
54
|
+
} = require('@aws-sdk/client-s3')
|
|
55
|
+
const mockS3Client = mockClient(S3Client)
|
|
13
56
|
|
|
14
57
|
const originalProgram = {
|
|
15
58
|
packageManager: 'npm',
|
|
@@ -19,7 +62,7 @@ const originalProgram = {
|
|
|
19
62
|
sessionToken: 'token',
|
|
20
63
|
functionName: '___node-lambda',
|
|
21
64
|
handler: 'index.handler',
|
|
22
|
-
role: '
|
|
65
|
+
role: 'arn:aws:iam::999999999999:role/test',
|
|
23
66
|
memorySize: 128,
|
|
24
67
|
timeout: 3,
|
|
25
68
|
description: '',
|
|
@@ -97,70 +140,59 @@ const lambdaMockSettings = {
|
|
|
97
140
|
tagResource: {}
|
|
98
141
|
}
|
|
99
142
|
|
|
100
|
-
const _mockSetting = () => {
|
|
101
|
-
awsMock.mock('CloudWatchEvents', 'putRule', (params, callback) => {
|
|
102
|
-
callback(null, {})
|
|
103
|
-
})
|
|
104
|
-
awsMock.mock('CloudWatchEvents', 'putTargets', (params, callback) => {
|
|
105
|
-
callback(null, {})
|
|
106
|
-
})
|
|
107
|
-
awsMock.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
|
|
108
|
-
callback(null, {})
|
|
109
|
-
})
|
|
110
|
-
awsMock.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
|
|
111
|
-
callback(null, {})
|
|
112
|
-
})
|
|
113
|
-
awsMock.mock('S3', 'putBucketNotificationConfiguration', (params, callback) => {
|
|
114
|
-
callback(null, {})
|
|
115
|
-
})
|
|
116
|
-
awsMock.mock('S3', 'putObject', (params, callback) => {
|
|
117
|
-
callback(null, { test: 'putObject' })
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
Object.keys(lambdaMockSettings).forEach((method) => {
|
|
121
|
-
awsMock.mock('Lambda', method, (params, callback) => {
|
|
122
|
-
callback(null, lambdaMockSettings[method])
|
|
123
|
-
})
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
return require('aws-sdk')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const _awsRestore = () => {
|
|
130
|
-
awsMock.restore('CloudWatchEvents')
|
|
131
|
-
awsMock.restore('CloudWatchLogs')
|
|
132
|
-
awsMock.restore('S3')
|
|
133
|
-
awsMock.restore('Lambda')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
143
|
/* global before, after, beforeEach, afterEach, describe, it */
|
|
137
144
|
describe('lib/main', function () {
|
|
138
|
-
if (
|
|
139
|
-
// It seems that it takes time for file operation in Windows
|
|
145
|
+
if (process.platform === 'win32') {
|
|
146
|
+
// It seems that it takes very long time for file operation in Windows.
|
|
147
|
+
// So set `timeout(300000)` for the whole test.
|
|
148
|
+
this.timeout(300000)
|
|
149
|
+
} else if (process.platform === 'darwin') {
|
|
150
|
+
// It seems that it takes time for file operation in Mac.
|
|
140
151
|
// So set `timeout(120000)` for the whole test.
|
|
141
152
|
this.timeout(120000)
|
|
142
153
|
}
|
|
143
154
|
|
|
144
|
-
let aws = null // mock
|
|
145
|
-
let awsLambda = null // mock
|
|
146
155
|
before(() => {
|
|
147
|
-
aws = _mockSetting()
|
|
148
|
-
awsLambda = new aws.Lambda({ apiVersion: '2015-03-31' })
|
|
149
|
-
|
|
150
156
|
if (process.platform === 'win32') {
|
|
151
157
|
execFileSync('cmd.exe', ['/c', 'npm', 'ci'], { cwd: sourceDirectoryForTest })
|
|
152
158
|
return
|
|
153
159
|
}
|
|
154
160
|
execFileSync('npm', ['ci'], { cwd: sourceDirectoryForTest })
|
|
155
161
|
})
|
|
156
|
-
after(() => _awsRestore())
|
|
157
162
|
|
|
158
163
|
beforeEach(() => {
|
|
159
164
|
program = Object.assign({}, originalProgram) // clone
|
|
165
|
+
|
|
166
|
+
mockLambdaClient.reset()
|
|
167
|
+
mockLambdaClient.on(AddPermissionCommand).resolves(lambdaMockSettings.addPermission)
|
|
168
|
+
mockLambdaClient.on(CreateEventSourceMappingCommand).resolves(lambdaMockSettings.createEventSourceMapping)
|
|
169
|
+
mockLambdaClient.on(CreateFunctionCommand).resolves(lambdaMockSettings.createFunction)
|
|
170
|
+
mockLambdaClient.on(DeleteEventSourceMappingCommand).resolves(lambdaMockSettings.deleteEventSourceMapping)
|
|
171
|
+
mockLambdaClient.on(GetFunctionCommand).resolves(lambdaMockSettings.getFunction)
|
|
172
|
+
mockLambdaClient.on(ListEventSourceMappingsCommand).resolves(lambdaMockSettings.listEventSourceMappings)
|
|
173
|
+
mockLambdaClient.on(ListTagsCommand).resolves(lambdaMockSettings.listTags)
|
|
174
|
+
mockLambdaClient.on(TagResourceCommand).resolves(lambdaMockSettings.tagResource)
|
|
175
|
+
mockLambdaClient.on(UntagResourceCommand).resolves(lambdaMockSettings.untagResource)
|
|
176
|
+
mockLambdaClient.on(UpdateEventSourceMappingCommand).resolves(lambdaMockSettings.updateEventSourceMapping)
|
|
177
|
+
mockLambdaClient.on(UpdateFunctionCodeCommand).resolves(lambdaMockSettings.updateFunctionCode)
|
|
178
|
+
mockLambdaClient.on(UpdateFunctionConfigurationCommand).resolves(lambdaMockSettings.updateFunctionConfiguration)
|
|
179
|
+
|
|
180
|
+
mockCloudWatchLogsClient.reset()
|
|
181
|
+
mockCloudWatchLogsClient.on(CreateLogGroupCommand).resolves({})
|
|
182
|
+
mockCloudWatchLogsClient.on(PutRetentionPolicyCommand).resolves({})
|
|
183
|
+
|
|
184
|
+
mockCloudWatchEventsClient.reset()
|
|
185
|
+
mockCloudWatchEventsClient.on(PutRuleCommand).resolves({})
|
|
186
|
+
mockCloudWatchEventsClient.on(PutTargetsCommand).resolves({})
|
|
187
|
+
|
|
188
|
+
mockS3Client.reset()
|
|
189
|
+
mockS3Client.on(CreateBucketCommand).resolves({})
|
|
190
|
+
mockS3Client.on(PutBucketNotificationConfigurationCommand).resolves({})
|
|
191
|
+
mockS3Client.on(PutObjectCommand).resolves({})
|
|
160
192
|
})
|
|
161
193
|
|
|
162
194
|
it('version should be set', () => {
|
|
163
|
-
assert.equal(lambda.version, '
|
|
195
|
+
assert.equal(lambda.version, '2.0.0-alpha.0')
|
|
164
196
|
})
|
|
165
197
|
|
|
166
198
|
describe('_codeDirectory', () => {
|
|
@@ -1333,7 +1365,7 @@ describe('lib/main', function () {
|
|
|
1333
1365
|
describe('_listEventSourceMappings', () => {
|
|
1334
1366
|
it('simple test with mock', () => {
|
|
1335
1367
|
return lambda._listEventSourceMappings(
|
|
1336
|
-
|
|
1368
|
+
lambdaClient,
|
|
1337
1369
|
{ FunctionName: 'test-func' }
|
|
1338
1370
|
).then((results) => {
|
|
1339
1371
|
assert.deepEqual(
|
|
@@ -1397,7 +1429,7 @@ describe('lib/main', function () {
|
|
|
1397
1429
|
program.eventSourceFile = ''
|
|
1398
1430
|
const eventSourceList = lambda._eventSourceList(program)
|
|
1399
1431
|
return lambda._updateEventSources(
|
|
1400
|
-
|
|
1432
|
+
lambdaClient,
|
|
1401
1433
|
'',
|
|
1402
1434
|
[],
|
|
1403
1435
|
eventSourceList.EventSourceMappings
|
|
@@ -1410,7 +1442,7 @@ describe('lib/main', function () {
|
|
|
1410
1442
|
program.eventSourceFile = 'event_sources.json'
|
|
1411
1443
|
const eventSourceList = lambda._eventSourceList(program)
|
|
1412
1444
|
return lambda._updateEventSources(
|
|
1413
|
-
|
|
1445
|
+
lambdaClient,
|
|
1414
1446
|
'functionName',
|
|
1415
1447
|
[],
|
|
1416
1448
|
eventSourceList.EventSourceMappings
|
|
@@ -1421,7 +1453,7 @@ describe('lib/main', function () {
|
|
|
1421
1453
|
|
|
1422
1454
|
it('simple test with mock (In case of deletion)', () => {
|
|
1423
1455
|
return lambda._updateEventSources(
|
|
1424
|
-
|
|
1456
|
+
lambdaClient,
|
|
1425
1457
|
'functionName',
|
|
1426
1458
|
lambdaMockSettings.listEventSourceMappings.EventSourceMappings,
|
|
1427
1459
|
{}
|
|
@@ -1434,7 +1466,7 @@ describe('lib/main', function () {
|
|
|
1434
1466
|
program.eventSourceFile = 'event_sources.json'
|
|
1435
1467
|
const eventSourceList = lambda._eventSourceList(program)
|
|
1436
1468
|
return lambda._updateEventSources(
|
|
1437
|
-
|
|
1469
|
+
lambdaClient,
|
|
1438
1470
|
'functionName',
|
|
1439
1471
|
lambdaMockSettings.listEventSourceMappings.EventSourceMappings,
|
|
1440
1472
|
eventSourceList.EventSourceMappings
|
|
@@ -1462,7 +1494,7 @@ describe('lib/main', function () {
|
|
|
1462
1494
|
'event_sources.json',
|
|
1463
1495
|
JSON.stringify(eventSourcesJsonValue)
|
|
1464
1496
|
)
|
|
1465
|
-
schedule = new ScheduleEvents(
|
|
1497
|
+
schedule = new ScheduleEvents({ region: 'us-east-1' })
|
|
1466
1498
|
})
|
|
1467
1499
|
|
|
1468
1500
|
after(() => fs.unlinkSync('event_sources.json'))
|
|
@@ -1514,7 +1546,7 @@ describe('lib/main', function () {
|
|
|
1514
1546
|
'event_sources.json',
|
|
1515
1547
|
JSON.stringify(eventSourcesJsonValue)
|
|
1516
1548
|
)
|
|
1517
|
-
s3Events = new S3Events(
|
|
1549
|
+
s3Events = new S3Events({ region: 'us-east-1' })
|
|
1518
1550
|
})
|
|
1519
1551
|
|
|
1520
1552
|
after(() => fs.unlinkSync('event_sources.json'))
|
|
@@ -1552,7 +1584,7 @@ describe('lib/main', function () {
|
|
|
1552
1584
|
describe('_uploadNew', () => {
|
|
1553
1585
|
it('simple test with mock', () => {
|
|
1554
1586
|
const params = lambda._params(program, null)
|
|
1555
|
-
return lambda._uploadNew(
|
|
1587
|
+
return lambda._uploadNew(lambdaClient, params, (results) => {
|
|
1556
1588
|
assert.deepEqual(results, lambdaMockSettings.createFunction)
|
|
1557
1589
|
})
|
|
1558
1590
|
})
|
|
@@ -1561,7 +1593,7 @@ describe('lib/main', function () {
|
|
|
1561
1593
|
describe('_uploadExisting', () => {
|
|
1562
1594
|
it('simple test with mock', () => {
|
|
1563
1595
|
const params = lambda._params(program, null)
|
|
1564
|
-
return lambda._uploadExisting(
|
|
1596
|
+
return lambda._uploadExisting(lambdaClient, params).then((results) => {
|
|
1565
1597
|
assert.deepEqual(results, lambdaMockSettings.updateFunctionConfiguration)
|
|
1566
1598
|
})
|
|
1567
1599
|
})
|
|
@@ -1572,7 +1604,7 @@ describe('lib/main', function () {
|
|
|
1572
1604
|
it('simple test with mock', () => {
|
|
1573
1605
|
const params = lambda._params(program, null)
|
|
1574
1606
|
return lambda._setLogsRetentionPolicy(
|
|
1575
|
-
new CloudWatchLogs(
|
|
1607
|
+
new CloudWatchLogs({ region: 'us-east-1' }),
|
|
1576
1608
|
program,
|
|
1577
1609
|
params.FunctionName
|
|
1578
1610
|
).then((results) => {
|
|
@@ -1649,7 +1681,7 @@ describe('lib/main', function () {
|
|
|
1649
1681
|
describe('Lambda.prototype._updateTags()', () => {
|
|
1650
1682
|
it('simple test with mock', () => {
|
|
1651
1683
|
return lambda._updateTags(
|
|
1652
|
-
|
|
1684
|
+
lambdaClient,
|
|
1653
1685
|
'arn:aws:lambda:eu-central-1:1234567:function:test',
|
|
1654
1686
|
{ tagKey: 'tagValue' }).then((result) => {
|
|
1655
1687
|
assert.deepEqual(
|
package/test/node-lambda.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let assert
|
|
4
|
+
import('chai').then(chai => {
|
|
5
|
+
assert = chai.assert
|
|
6
|
+
})
|
|
4
7
|
const process = require('process')
|
|
5
8
|
const path = require('path')
|
|
6
9
|
const fs = require('fs-extra')
|
|
@@ -8,6 +11,11 @@ const spawn = require('child_process').spawn
|
|
|
8
11
|
const execSync = require('child_process').execSync
|
|
9
12
|
const nodeLambdaPath = path.join(__dirname, '..', 'bin', 'node-lambda')
|
|
10
13
|
|
|
14
|
+
const removeDotenvLog = (str) => {
|
|
15
|
+
// eslint-disable-next-line no-control-regex
|
|
16
|
+
return str.replace(/^\u001b\[38;5;142m\[dotenvx@.+\]injectingenv\(.+\)from.env\u001b\[39m/, '')
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
/* global before, after, describe, it */
|
|
12
20
|
// The reason for specifying the node command in this test is to support Windows.
|
|
13
21
|
describe('bin/node-lambda', () => {
|
|
@@ -257,7 +265,7 @@ describe('bin/node-lambda', () => {
|
|
|
257
265
|
'{asyncTest:false,callbackWaitsForEmptyEventLoop:true,callbackCode:\'callback(null);\',no:3}]' +
|
|
258
266
|
'==================================Stoppingindex.handlerSuccess:'
|
|
259
267
|
|
|
260
|
-
assert.equal(stdoutString, expected)
|
|
268
|
+
assert.equal(removeDotenvLog(stdoutString), expected)
|
|
261
269
|
assert.equal(code, 0)
|
|
262
270
|
done()
|
|
263
271
|
})
|
|
@@ -289,7 +297,7 @@ describe('bin/node-lambda', () => {
|
|
|
289
297
|
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Runningindex.handler==================================event' +
|
|
290
298
|
'{body:\'{"asyncTest":false,"callbackWaitsForEmptyEventLoop":true,"callbackCode":"callback(null);"}\'}' +
|
|
291
299
|
'==================================Stoppingindex.handlerSuccess:'
|
|
292
|
-
assert.equal(stdoutString, expected)
|
|
300
|
+
assert.equal(removeDotenvLog(stdoutString), expected)
|
|
293
301
|
assert.equal(code, 0)
|
|
294
302
|
done()
|
|
295
303
|
})
|
|
@@ -313,7 +321,7 @@ describe('bin/node-lambda', () => {
|
|
|
313
321
|
'event{asyncTest:false,callbackWaitsForEmptyEventLoop:true,callbackCode:\'callback(null);\'}' +
|
|
314
322
|
'==================================' +
|
|
315
323
|
'Stoppingindex.handler(mjs)Success:'
|
|
316
|
-
assert.equal(stdoutString, expected)
|
|
324
|
+
assert.equal(removeDotenvLog(stdoutString), expected)
|
|
317
325
|
assert.equal(code, 0)
|
|
318
326
|
done()
|
|
319
327
|
})
|
|
@@ -336,7 +344,7 @@ describe('bin/node-lambda', () => {
|
|
|
336
344
|
})
|
|
337
345
|
|
|
338
346
|
run.on('exit', (code) => {
|
|
339
|
-
assert.equal(stdoutString, '')
|
|
347
|
+
assert.equal(removeDotenvLog(stdoutString), '')
|
|
340
348
|
assert.match(stderrString, /Handler file not found\./)
|
|
341
349
|
assert.equal(code, 255)
|
|
342
350
|
done()
|
|
@@ -380,7 +388,10 @@ describe('bin/node-lambda', () => {
|
|
|
380
388
|
const packageJson = require(path.join(__dirname, '..', 'package.json'))
|
|
381
389
|
it('The current version is displayed', () => {
|
|
382
390
|
const ret = execSync(`node ${nodeLambdaPath} --version`)
|
|
383
|
-
assert.equal(
|
|
391
|
+
assert.equal(
|
|
392
|
+
ret.toString().trim().split('\n').pop(),
|
|
393
|
+
packageJson.version
|
|
394
|
+
)
|
|
384
395
|
})
|
|
385
396
|
})
|
|
386
397
|
})
|
package/test/s3_deploy.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let assert
|
|
4
|
+
import('chai').then(chai => {
|
|
5
|
+
assert = chai.assert
|
|
6
|
+
})
|
|
4
7
|
const process = require('process')
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const {
|
|
9
|
+
S3Client,
|
|
10
|
+
CreateBucketCommand,
|
|
11
|
+
PutObjectCommand
|
|
12
|
+
} = require('@aws-sdk/client-s3')
|
|
13
|
+
const { mockClient } = require('aws-sdk-client-mock')
|
|
14
|
+
const mockS3Client = mockClient(S3Client)
|
|
8
15
|
const S3Deploy = require('../lib/s3_deploy')
|
|
9
16
|
|
|
10
17
|
const mockResponse = {
|
|
@@ -17,18 +24,11 @@ let s3Deploy = null
|
|
|
17
24
|
/* global describe, it, before, after */
|
|
18
25
|
describe('lib/s3_deploy', () => {
|
|
19
26
|
before(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
aws.mock('S3', 'createBucket', (params, callback) => {
|
|
24
|
-
callback(null, mockResponse.createBucket)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
s3Deploy = new S3Deploy(require('aws-sdk'))
|
|
28
|
-
})
|
|
27
|
+
mockS3Client.reset()
|
|
28
|
+
mockS3Client.on(CreateBucketCommand).resolves(mockResponse.createBucket)
|
|
29
|
+
mockS3Client.on(PutObjectCommand).resolves(mockResponse.putObject)
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
aws.restore('S3')
|
|
31
|
+
s3Deploy = new S3Deploy({ region: 'us-west-1' })
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
describe('_md5', () => {
|