-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdynamo_user_table.ts
39 lines (37 loc) · 1.02 KB
/
dynamo_user_table.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
import { ApiFactory, DynamoDB } from "./deps.ts";
import {
DYNAMO_ACCESS_KEY_ID,
DYNAMO_REGION,
DYNAMO_SECRET_ACCESS_KEY,
DYNAMO_USER_TABLE,
} from "../util/constants.ts";
export const client = new ApiFactory({
region: DYNAMO_REGION,
credentials: {
awsAccessKeyId: DYNAMO_ACCESS_KEY_ID,
awsSecretKey: DYNAMO_SECRET_ACCESS_KEY,
},
}).makeNew(DynamoDB);
try {
await client.describeTable({
TableName: DYNAMO_USER_TABLE,
});
console.log("Table already exists");
} catch (err) {
console.log("Table not found");
if (err.name === "ResourceNotFoundException") {
console.log("Creating table");
await client.createTable({
TableName: DYNAMO_USER_TABLE,
AttributeDefinitions: [{ AttributeName: "id", AttributeType: "N" }],
KeySchema: [{ AttributeName: "id", KeyType: "HASH" }],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
});
} else {
console.log("Unexpected error");
console.log(JSON.stringify(err, undefined, 2));
}
}