forked from NathanTarbert/voting-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamo.js
44 lines (37 loc) · 1.2 KB
/
dynamo.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
43
44
const { DynamoDBClient, GetItemCommand, PutItemCommand, ScanCommand } = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient({});
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/PutItemCommand/
export async function _putItem(tableName, item) {
const command = new PutItemCommand({
TableName: tableName,
Item: item,
});
console.log(command);
const response = await client.send(command);
console.log(response);
return response;
}
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/GetItemCommand/
export async function _getItem(tableName, key) {
const command = new GetItemCommand({
TableName: tableName,
Key: key,
});
console.log(command);
const response = await client.send(command);
console.log(response);
if (!response.Item) {
return undefined;
}
return response;
}
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/ScanCommand/
export async function _scan(tableName) {
const command = new ScanCommand({
TableName: tableName,
});
console.log(command);
const response = await client.send(command);
console.log(response);
return response;
}