async function createIndex()

in DynamoDB-SDK-Examples/node.js/WorkingWithIndexes/CreateIndex.js [9:54]


async function createIndex() {
    const client = new DynamoDBClient({ region: REGION });
    try {
        return await client.send(
            new UpdateTableCommand({
                TableName: TableName,
                AttributeDefinitions: [
                    {
                        AttributeName: "SongTitle",
                        AttributeType: "S",
                    },
                    {
                        AttributeName: "Artist",
                        AttributeType: "S",
                    },
                ],
                GlobalSecondaryIndexUpdates: [ {
                    Create: {
                        IndexName: IndexName,

                        KeySchema: [
                            {
                                AttributeName: "SongTitle",
                                KeyType: "HASH", // Partition key
                            },
                            {
                                AttributeName: "Artist",
                                KeyType: "RANGE", // Sort key
                            },
                        ],
                        Projection: {
                            ProjectionType : "ALL"
                        },
                        // If the base table is in on-demand mode, the ProvisionedThroughput object can be omitted entirely.
                        ProvisionedThroughput: {
                            ReadCapacityUnits: 5,
                            WriteCapacityUnits: 5,
                        },
                    }
                }],
            },)
        );
    } catch (err) {
        console.error(err);
    }
}