-
Notifications
You must be signed in to change notification settings - Fork 1
/
michonne.py
56 lines (45 loc) · 1.52 KB
/
michonne.py
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
import AWS from "aws-sdk";
AWS.config.update({ region: "us-east-1" });
const dynamodb = new AWS.DynamoDB.DocumentClient();
export function main(event, context, callback) {
const queryPage = event.pathParameters.page;
if (queryPage < 0){
callback(null, {
statusCode: 500,
headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Credentials" : true
},
body: JSON.stringify({data: 'index out of range'})
});
return;
}
const qParams = {
TableName: "random-products",
Key: {page: -1, id: -1}
};
dynamodb.get(qParams).promise().then((data) => {
console.log(data);
callback(null, {
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({
outDynamo: data,
input: event,
}),
});
}).catch((err) => {
callback(null, {
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({ err })
});
return;
});
}