-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (52 loc) · 1.7 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
60
61
62
63
64
65
'use strict';
console.log('Loading hello world function');
exports.handler = async (event) => {
let name = "you";
let City = 'World';
let time = 'day';
let dayOfTheWeekInStandardEnglishForm = '';
let response_code = 200;
console.log ("request: " + JSON.stringify(event));
if (event.queryStringParameters && event.queryStringParameters.name)
{
let message = "Received name: " + event.queryStringParameters.name
console.log(message);
name = event.queryStringParameters.name;
}
if (event.queryStringParameters
&& event.queryStringParameters.city) {
City = event.queryStringParameters.city;
console.log("Received city: " + City);
}
if (event.headers && event.headers['day'])
{
console.log("Received day: "
+ event.headers.day);
dayOfTheWeekInStandardEnglishForm = event.headers.day;
}
if (event.body) {
let body = JSON.parse(event.body)
if (body.time)
time = body.time;
}
let greeting = `Good ${time}, ${name} of ${City}.`;
if (dayOfTheWeekInStandardEnglishForm) greeting += ` Happy ${dayOfTheWeekInStandardEnglishForm}!` ;
let responseBody = { message: greeting,
input: event
};
let response = {
statusCode: response_code,
headers: {"x-custom-header" : "my custom header value"
},
body:
JSON.stringify(responseBody)
};
console.log("response: " + JSON.stringify(response))
return {
statusCode: response_code,
headers: {"x-custom-header" : "my custom header value"
},
body:
JSON.stringify(responseBody)
};
};