Skip to content

Commit e8deff3

Browse files
committed
On branch master
Initial commit Changes to be committed: new file: index.js new file: package.json
0 parents  commit e8deff3

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
var exec = require('child_process').exec;
4+
var fs = require('fs');
5+
6+
var invokeFolder = process.cwd();
7+
8+
var command;
9+
10+
function execute(command) {
11+
exec(command, function(err, stdout, stderr) {
12+
if (err) {
13+
console.log(err);
14+
} else if (stderr) {
15+
console.log('stderr', stderr);
16+
} else {
17+
console.log('stdout:', stdout);
18+
}
19+
});
20+
}
21+
22+
if (invokeFolder.indexOf('lambdafns') == -1) {
23+
console.log('You are in the wrong folder, path must be under lambdafns');
24+
} else {
25+
command = 'aws lambda invoke --function-name ${PWD##*/} outfile';
26+
// if we have payload
27+
if(process.argv[2]) {
28+
fs.readFile(process.argv[2], function(err, data) {
29+
if(err) {
30+
throw err;
31+
} else {
32+
console.log('data');
33+
var payloadFile = JSON.parse(data.toString('utf-8'));
34+
payloadFile = JSON.stringify(payloadFile);
35+
payloadFile = payloadFile.replace(/"/g, '\\"');
36+
command += ' --payload "' + payloadFile + '"';
37+
console.log('command: ', command);
38+
39+
execute(command);
40+
}
41+
});
42+
} else {
43+
execute(command);
44+
}
45+
}

Diff for: package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "runlambda",
3+
"version": "1.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"preferGlobal": true,
13+
"bin": {
14+
"runlambda": "index.js"
15+
}
16+
}

0 commit comments

Comments
 (0)