forked from aws-samples/aws-serverless-workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth-check.js
More file actions
55 lines (37 loc) · 1.42 KB
/
health-check.js
File metadata and controls
55 lines (37 loc) · 1.42 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';
const AWS = require("aws-sdk");
const table = process.env.TABLE_NAME;
exports.handler = (event, context, callback) => {
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: table
};
docClient.scan(params, function (err, data) {
let response = {};
let body = {};
body.region = process.env.AWS_REGION;
if (err) {
console.log(JSON.stringify(err, null, 2));
body.message = ("Could not read from DynamoDB table.");
response = {
statusCode: 500,
headers: {
"Access-Control-Allow-Origin" : "*", // Required for CORS support to work
"Access-Control-Allow-Credentials" : true // Required for cookies, authorization headers with HTTPS
},
body: JSON.stringify(body)
};
} else {
body.message = ("Successful response reading from DynamoDB table.");
response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*", // Required for CORS support to work
"Access-Control-Allow-Credentials" : true // Required for cookies, authorization headers with HTTPS
},
body: JSON.stringify(body)
};
}
callback(null, response);
});
};