-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlambda.js
43 lines (35 loc) · 1.12 KB
/
lambda.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
require('dotenv').load();
const { google } = require('googleapis');
const googleAuth = require('./lib/google-auth');
const queryToSheet = require('./lib/query-to-sheet');
exports.handler = async (event, context) => {
console.log('context: ', context);
console.log('remaining time =', context.getRemainingTimeInMillis());
if (process.env.LAMBDA_DEBUG_LOG) {
console.log('LAMBDA EVENT', event);
}
if (event.env) {
Object.entries(event.env).forEach((a) => {
process.env[a] = event.env[a];
console.log('processing events env');
});
}
if (!event.command) {
console.log('no event command, running script');
if (!event.config) throw new Error('event.config is required');
try {
const googleSheets = google.sheets({
version: 'v4',
auth: await googleAuth(),
});
await queryToSheet(googleSheets)(event.config);
console.log('done index');
console.log('remaining time =', context.getRemainingTimeInMillis());
} catch (err) {
console.log('error loading index: ', err);
throw err;
}
} else {
console.log(event.command);
}
};