-
Notifications
You must be signed in to change notification settings - Fork 0
/
getHighlights.js
42 lines (36 loc) · 1.03 KB
/
getHighlights.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
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: "ap-southeast-2"});
exports.handler = (event, context, callback) => {
console.log("Processing...");
var params
if (event.key === 'all') {params = {
TableName: "highlights"
};}
else {
params = {
ExpressionAttributeNames: {
"#tableKey": event.key
},
FilterExpression: "#tableKey = :searchTerm",
ExpressionAttributeValues: {
":searchTerm": event.term
},
TableName: "highlights"
};
}
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify("Processed")
};
docClient.scan(params, (err, data) => {
if(err){
callback(err, null);
} else {
callback(null, data);
}
});
};