-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
37 lines (34 loc) · 953 Bytes
/
handler.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
const AWS = require('aws-sdk');
const util = require('util');
const parser = require('ua-parser-js');
/**
*
* @param event
* @return {Promise<*>}
*/
exports.index = async (event) => {
// Log function input
const log = require('console-log-level')({
level : process.env.LOG_LEVEL,
});
log.trace(
'Start "user-agent" aggregation service: \n',
util.inspect(event),
);
try {
if (typeof event.context.userAgent === 'undefined') {
throw new Error('userAgent not available in event.context');
}
const result = parser(event.context.userAgent);
if (result) {
event.context.ua = result;
log.debug('User Agent information added to event.context: \n', util.inspect(result));
} else {
log.debug('No UserAgent data available for the submitted userAgent.');
}
return event;
} catch (err) {
log.error(`Error processing aggregation: ${err}`);
throw new Error(err);
}
};