-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupTable.ts
More file actions
62 lines (55 loc) · 1.58 KB
/
setupTable.ts
File metadata and controls
62 lines (55 loc) · 1.58 KB
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
57
58
59
60
61
62
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",
credentials: {
accessKeyId: "DUMMYIDEXAMPLE",
secretAccessKey: "DUMMYEXAMPLEKEY",
},
});
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();
} catch (err: any) {
if (err.__type !== "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException") {
console.log("Error deleting table", err);
process.exit(1);
}
}
try {
await createTable();
} catch (err) {
console.log("Error creating table", err);
process.exit(1);
}
};
run();