-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscan.mjs
39 lines (35 loc) · 1.18 KB
/
scan.mjs
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
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
import { createResponse } from '/opt/nodejs/sample-layer/utils.mjs';
const dynamodb = DynamoDBDocument.from(new DynamoDB({}));
const TABLE_NAME = process.env.TABLE_NAME;
let corsHeaders = {
'Access-Control-Allow-Origin': process.env.CORS_ORIGIN,
'Access-Control-Allow-Credentials': true,
};
export const handler = async (event) => {
return new Promise(async (resolve) => {
try {
// scan the table for unexpired results
const data = await dynamodb.scan({
TableName: TABLE_NAME
});
resolve(createResponse({
"statusCode": 200,
"headers": corsHeaders,
"body": data.Items
}));
} catch (err) {
console.error(err);
resolve(createResponse({
"statusCode": 500,
"headers": corsHeaders,
"body": {
"success": false,
"reason": "an unexpected error occurred",
"error": err
}
}));
}
});
}