create_lsi
Enables creation of a local secondary index during DynamoDB table setup, specifying keys, types, projection, and capacity units for efficient data querying.
Instructions
Creates a local secondary index on a table (must be done during table creation)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexName | Yes | Name of the new index | |
| nonKeyAttributes | No | Non-key attributes to project (optional) | |
| partitionKey | Yes | Partition key for the table | |
| partitionKeyType | Yes | Type of partition key | |
| projectionType | Yes | Type of projection | |
| readCapacity | No | Provisioned read capacity units (optional, default: 5) | |
| sortKey | Yes | Sort key for the index | |
| sortKeyType | Yes | Type of sort key | |
| tableName | Yes | Name of the table | |
| writeCapacity | No | Provisioned write capacity units (optional, default: 5) |
Implementation Reference
- src/index.ts:366-410 (handler)The handler function createLSI that executes the tool logic: creates a DynamoDB table with a local secondary index (LSI) using CreateTableCommand, since LSIs must be defined at table creation time.async function createLSI(params: any) { try { // Note: LSIs must be created during table creation, so we need the table's primary key info const command = new CreateTableCommand({ TableName: params.tableName, AttributeDefinitions: [ { AttributeName: params.partitionKey, AttributeType: params.partitionKeyType }, { AttributeName: params.sortKey, AttributeType: params.sortKeyType }, ], KeySchema: [ { AttributeName: params.partitionKey, KeyType: "HASH" as const }, ], LocalSecondaryIndexes: [ { IndexName: params.indexName, KeySchema: [ { AttributeName: params.partitionKey, KeyType: "HASH" as const }, { AttributeName: params.sortKey, KeyType: "RANGE" as const }, ], Projection: { ProjectionType: params.projectionType, ...(params.projectionType === "INCLUDE" ? { NonKeyAttributes: params.nonKeyAttributes } : {}), }, }, ], ProvisionedThroughput: { ReadCapacityUnits: params.readCapacity || 5, WriteCapacityUnits: params.writeCapacity || 5, }, }); const response = await dynamoClient.send(command); return { success: true, message: `LSI ${params.indexName} created on table ${params.tableName}`, details: response.TableDescription, }; } catch (error) { console.error("Error creating LSI:", error); return { success: false, message: `Failed to create LSI: ${error}`, }; } }
- src/index.ts:109-128 (schema)Tool definition including name, description, and input schema for validating parameters like tableName, indexName, keys, projection, etc.const CREATE_LSI_TOOL: Tool = { name: "create_lsi", description: "Creates a local secondary index on a table (must be done during table creation)", inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, indexName: { type: "string", description: "Name of the new index" }, partitionKey: { type: "string", description: "Partition key for the table" }, partitionKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of partition key" }, sortKey: { type: "string", description: "Sort key for the index" }, sortKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of sort key" }, projectionType: { type: "string", enum: ["ALL", "KEYS_ONLY", "INCLUDE"], description: "Type of projection" }, nonKeyAttributes: { type: "array", items: { type: "string" }, description: "Non-key attributes to project (optional)" }, readCapacity: { type: "number", description: "Provisioned read capacity units (optional, default: 5)" }, writeCapacity: { type: "number", description: "Provisioned write capacity units (optional, default: 5)" }, }, required: ["tableName", "indexName", "partitionKey", "partitionKeyType", "sortKey", "sortKeyType", "projectionType"], }, };
- src/index.ts:598-600 (registration)Registration of CREATE_LSI_TOOL in the list of available tools returned by ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [CREATE_TABLE_TOOL, UPDATE_CAPACITY_TOOL, PUT_ITEM_TOOL, GET_ITEM_TOOL, QUERY_TABLE_TOOL, SCAN_TABLE_TOOL, DESCRIBE_TABLE_TOOL, LIST_TABLES_TOOL, CREATE_GSI_TOOL, UPDATE_GSI_TOOL, CREATE_LSI_TOOL, UPDATE_ITEM_TOOL], }));
- src/index.ts:620-622 (registration)Dispatch registration in the CallToolRequestSchema switch statement that maps 'create_lsi' to the createLSI handler.case "create_lsi": result = await createLSI(args); break;