-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambdainvoke.js
executable file
·52 lines (46 loc) · 1.33 KB
/
lambdainvoke.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
const path = require('path')
const awskeys = require('./aws-credentials.json')
process.env['LAMBDA_TASK_ROOT'] = path.join(__dirname, '..')
process.env['AWS_ACCESS_KEY_ID'] = awskeys.AWS_ACCESS_KEY_ID
process.env['AWS_SECRET_ACCESS_KEY'] = awskeys.AWS_SECRET_ACCESS_KEY
var index = require('./' + (process.argv[2] || 'index.js'))
, handler = process.argv[3] || 'handler'
, event = require('./event.json')
, context = {
done: function (err, data) {
if (err) {
console.log("Error! " + err)
end()
} else {
console.log("Success! " + data)
end()
}
}
, succeed: function (data) {
console.log("Success! " + data)
end()
}
, fail: function (err) {
console.log("Error! " + err)
end()
}
}
, start = process.hrtime()
, end = function () {
contextCalled = true
console.log("--------------------------")
console.log("Execution time: %dms", process.hrtime(start)[1] / 1000000)
console.log("--------------------------")
process.exit()
}
, contextCalled = false
function exit(options, error) {
if (!contextCalled) {
console.log("--------------------------")
console.log('A context method was not called!')
console.log("--------------------------")
}
}
process.on('exit', exit)
index[handler](event, context)