-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
59 lines (51 loc) · 1.98 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const rookout = require('rookout/lambda');
exports.handler = rookout.wrap((event, context, callback) => {
let name = "you";
let city = 'World';
let time = 'day';
let day = '';
let responseCode = 200;
console.log("request: " + JSON.stringify(event));
if (event.queryStringParameters !== null && event.queryStringParameters !== undefined) {
if (event.queryStringParameters.name !== undefined &&
event.queryStringParameters.name !== null &&
event.queryStringParameters.name !== "") {
console.log("Received name: " + event.queryStringParameters.name);
name = event.queryStringParameters.name;
}
}
if (event.pathParameters !== null && event.pathParameters !== undefined) {
if (event.pathParameters.proxy !== undefined &&
event.pathParameters.proxy !== null &&
event.pathParameters.proxy !== "") {
console.log("Received proxy: " + event.pathParameters.proxy);
city = event.pathParameters.proxy;
}
}
if (event.headers !== null && event.headers !== undefined) {
if (event.headers['day'] !== undefined && event.headers['day'] !== null && event.headers['day'] !== "") {
console.log("Received day: " + event.headers.day);
day = event.headers.day;
}
}
if (event.body !== null && event.body !== undefined) {
let body = JSON.parse(event.body)
if (body.time)
time = body.time;
}
let greeting = 'Good ' + time + ', ' + name + ' of ' + city + '. ';
if (day) greeting += 'Happy ' + day + '!';
var responseBody = {
message: greeting,
input: event
};
var response = {
statusCode: responseCode,
headers: {
"x-custom-header" : "my custom header value"
},
body: JSON.stringify(responseBody)
};
console.log("response: " + JSON.stringify(response))
callback(null, response);
});