-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (35 loc) · 1.04 KB
/
index.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
var AWS = require('aws-sdk')
var s3 = new AWS.S3();
var params = {
Bucket: 'princetonhackbob',
Key: 'AlexaTest3.json'
};
var fileLoaded = false;
var fileData = null;
exports.handler = (event, context, callback) => {
if(!fileLoaded){
s3.getObject(params, function (err, data) {
if (err) console.log(err, err.stack);
else {
fileLoaded = true;
fileData = data;
parseJSON(event, context, callback)
}
});
} else {
parseJSON(event, context, callback)
}
};
function parseJSON(event, context, callback){
const spawnSync = require("child_process").spawnSync;
const pythonProcess = spawnSync('python',["./main.py", fileData.Body.toString()]);
var checkValue;
console.log(pythonProcess)
console.log(pythonProcess.stderr.toString())
console.log(pythonProcess.stdout.toString())
return callback(null, {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': true
})
}