forked from aws-samples/aws-dynamodb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table_on_demand.js
40 lines (35 loc) · 1.17 KB
/
create_table_on_demand.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
// A simple script to create an on-demand capacity mode DynamoDB table.
const { DynamoDBClient, CreateTableCommand } = require('@aws-sdk/client-dynamodb');
const REGION = "us-west-2";
const TableName = "Music";
const dbclient = new DynamoDBClient({ region: REGION });
async function createTable() {
const params = {
AttributeDefinitions: [
{
AttributeName: "Artist",
AttributeType: "S",
},
{
AttributeName: "SongTitle",
AttributeType: "S",
},
],
KeySchema: [
{
AttributeName: "Artist",
KeyType: "HASH", // Partition key
},
{
AttributeName: "SongTitle",
KeyType: "RANGE", // Sort key
},
],
BillingMode: "PAY_PER_REQUEST",
TableName: TableName, // Substitute your table name for "Music"
};
return await dbclient.send( new CreateTableCommand(params));
}
createTable()
.then((data) => console.log(data))
.catch((error) => console.log("An error occurred while creating the table:" + ' ' + error.message ));