-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.ts
37 lines (32 loc) · 923 Bytes
/
get.ts
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
'use strict';
import { APIGatewayProxyHandler } from 'aws-lambda';
import 'source-map-support/register';
import dynamoDb from './dynamodb'
export const getStats: APIGatewayProxyHandler = (_event, _context, callback) => {
const params = {
TableName: process.env.STATS_TABLE,
ScanIndexForward: "false",
Limit: 1
};
dynamoDb.scan(params, (error, result) => {
if (error) {
console.error(error);
callback(null, {
statusCode: error.statusCode || 501,
headers: { 'Content-Type': 'text/plain' },
body: 'Couldn\'t fetch the count.',
});
return;
}
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin' : '*' // Required for CORS support to work
},
body: JSON.stringify({
count: result.Items[0] ? result.Items[0].count : 0
}, null, 2),
};
callback(null, response);
});
};