-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplefunction1.txt
More file actions
49 lines (34 loc) · 1.3 KB
/
samplefunction1.txt
File metadata and controls
49 lines (34 loc) · 1.3 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
'use strict'; //cannot use vars that are not defined
console.log('loading sample function 1.....');
//function needs to be exported
//cjs = commonJS, require(),module exports <---- nodejs <14
//es m = import, export const function1 = () => {} <--nodejs >=16
//user request is in JSON format
export const handler = async(event) =>{
let name = 'John';
let city = 'Manila';
let responseCode = 200;
console.log("request:" + JSON.stringify(event));
if(event.queryStringParameter && event.queryStringParameter.name){
console.log("received name:" + event.queryStringParameter.name);
name = event.queryStringParameter.name;
}
if(event.queryStringParameter && event.queryStringParameter.city){
console.log("received city:" + event.queryStringParameter.city);
city = event.queryStringParameter.city;
}
let greeting = `Good day ${name} of ${city}`;
let responseBody = {
message: greeting,
input: event
}
let response = {
statusCode: responseCode,
headers: {
"x-custom-header": "my custom header value"
},
body: JSON.stringify(responseBody);
}
console.log("response:" + JSON.stringify(response));
return response;
}