-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
63 lines (52 loc) · 1.57 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* This file is an example AWS Lambda function.
* The Moesif AWS Lambda SDK is in the ./lib directory
*/
const moesif = require('./lib');
var http = require('http');
var https = require('https');
console.log('Loading function');
const moesifOptions = {
applicationId: process.env.MOESIF_APPLICATION_ID,
identifyUser: function (event, context) {
return event.requestContext && event.requestContext.identity && event.requestContext.identity.cognitoIdentityId
}
};
var moesifMiddleware = moesif(moesifOptions);
moesifMiddleware.startCaptureOutgoing();
var handler = function (event, context, callback) {
// Outgoing API call to third party
https.get(
{
host: 'jsonplaceholder.typicode.com',
path: '/posts/1'
},
function(res) {
var body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
var parsed = JSON.parse(body);
console.log(parsed);
});
}
);
callback(null, {
statusCode: '200',
body: JSON.stringify({key: 'hello world'}),
headers: {
'Content-Type': 'application/json'
}
});
};
// Async Functions
// For more details, please refer to - https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html.
// exports.handler = async (event, context) => {
// const response = {
// statusCode: 200,
// body: JSON.stringify({ message: 'hello world' })
// }
// return response
// }
exports.handler = moesif(moesifOptions, handler);