Skip to content

Commit 591c43b

Browse files
committed
Checks for alias to invoke the correct version, and if not found, runs $LATEST. Added colors module
and colored output. Added use strict. On branch master Changes to be committed: new file: .gitignore modified: index.js new file: package-lock.json modified: package.json
1 parent e8deff3 commit 591c43b

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Diff for: index.js

+39-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env node
22

3-
var exec = require('child_process').exec;
4-
var fs = require('fs');
3+
"use strict";
4+
5+
const exec = require('child_process').exec;
6+
const fs = require('fs');
7+
const colors = require('colors');
58

69
var invokeFolder = process.cwd();
710

@@ -19,27 +22,39 @@ function execute(command) {
1922
});
2023
}
2124

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-
});
25+
fs.readFile('package.json', 'utf-8', function(err, data) {
26+
if (err) {
27+
throw (err);
4228
} else {
43-
execute(command);
29+
data = JSON.parse(data.toString('utf-8'));
30+
let functionName = data.name;
31+
32+
command = `aws lambda invoke --function-name ${functionName} outfile`;
33+
34+
if(data.lambdaAlias) {
35+
console.log(colors.blue('Running lambda alias:', data.lambdaAlias));
36+
command += ` --qualifier ${data.lambdaAlias}`;
37+
} else{
38+
console.log(colors.blue('Running lambda $LATEST, no lambdaAlias found in package.json'));
39+
}
40+
// if we have payload
41+
if (process.argv[2]) {
42+
fs.readFile(process.argv[2], function(err, data) {
43+
if (err) {
44+
throw err;
45+
} else {
46+
console.log('data');
47+
var payloadFile = JSON.parse(data.toString('utf-8'));
48+
payloadFile = JSON.stringify(payloadFile);
49+
payloadFile = payloadFile.replace(/"/g, '\\"');
50+
command += ' --payload "' + payloadFile + '"';
51+
console.log('command: ', command);
52+
53+
execute(command);
54+
}
55+
});
56+
} else {
57+
execute(command);
58+
}
4459
}
45-
}
60+
});

Diff for: package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
"preferGlobal": true,
1313
"bin": {
1414
"runlambda": "index.js"
15+
},
16+
"dependencies": {
17+
"colors": "^1.1.2"
1518
}
1619
}

0 commit comments

Comments
 (0)