-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (47 loc) · 1.58 KB
/
index.js
File metadata and controls
55 lines (47 loc) · 1.58 KB
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
"use strict";
console.log("Loading hello world function");
exports.handler = async (event) => {
let name = "you";
let city = "World";
let time = "day";
let day = "";
let responseCode = 200;
console.log("request: " + JSON.stringify(event));
if (event.queryStringParameters && event.queryStringParameters.name) {
console.log("Received name: " + event.queryStringParameters.name);
name = event.queryStringParameters.name;
}
if (event.queryStringParameters && event.queryStringParameters.city) {
console.log("Received city: " + event.queryStringParameters.city);
city = event.queryStringParameters.city;
}
if (event.headers && event.headers["day"]) {
console.log("Received day: " + event.headers.day);
day = 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 (day) greeting += ` Happy ${day}!`;
let responseBody = {
message: greeting,
input: event,
};
// The output from a Lambda proxy integration must be
// in the following JSON object. The 'headers' property
// is for custom response headers in addition to standard
// ones. The 'body' property must be a JSON string. For
// base64-encoded payload, you must also set the 'isBase64Encoded'
// property to 'true'.
let response = {
statusCode: responseCode,
headers: {
"x-custom-header": "my custom header value",
},
body: JSON.stringify(responseBody),
};
console.log("response: " + JSON.stringify(response));
return response;
};