-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTable.ts
47 lines (40 loc) · 1.24 KB
/
setupTable.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
38
39
40
41
42
43
44
45
46
47
import { DynamoDBClient, CreateTableCommand, CreateTableCommandInput, DeleteTableCommandInput, DeleteTableCommand } from "@aws-sdk/client-dynamodb";
const REGION = "us-east-1";
const client = new DynamoDBClient({ region: REGION, endpoint: "http://localhost:8000" });
const createTable = async () => {
const params: CreateTableCommandInput = {
TableName: "idempotency",
AttributeDefinitions: [
{ AttributeName: "PK", AttributeType: "S" },
{ AttributeName: "SK", AttributeType: "S" },
],
KeySchema: [
{ AttributeName: "PK", KeyType: "HASH" },
{ AttributeName: "SK", KeyType: "RANGE" },
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
},
};
const data = await client.send(new CreateTableCommand(params));
console.log("Table Created", data);
return data;
}
const deleteTable = async () => {
const params: DeleteTableCommandInput = {
TableName: "idempotency",
};
const data = await client.send(new DeleteTableCommand(params));
console.log("Table Deleted", data);
return data;
}
const run = async () => {
try {
await deleteTable();
await createTable();
} catch (err) {
console.log("Error", err);
}
};
run();